@@ -429,7 +429,7 @@ function unstable_getCurrentPriorityLevel() {
429
429
return currentPriorityLevel ;
430
430
}
431
431
432
- let isMessageLoopRunning = false ;
432
+ let isTaskLoopRunning = false ;
433
433
let scheduledHostCallback = null ;
434
434
let taskTimeoutID = - 1 ;
435
435
@@ -522,38 +522,39 @@ const performWorkUntilDeadline = () => {
522
522
try {
523
523
const hasMoreWork = scheduledHostCallback ( hasTimeRemaining , currentTime ) ;
524
524
if ( ! hasMoreWork ) {
525
- isMessageLoopRunning = false ;
525
+ isTaskLoopRunning = false ;
526
526
scheduledHostCallback = null ;
527
527
} else {
528
528
// If there's more work, schedule the next message event at the end
529
529
// of the preceding one.
530
- port . postMessage ( null ) ;
530
+ postTask ( performWorkUntilDeadline ) ;
531
531
}
532
532
} catch ( error ) {
533
533
// If a scheduler task throws, exit the current browser task so the
534
534
// error can be observed.
535
- port . postMessage ( null ) ;
535
+ postTask ( performWorkUntilDeadline ) ;
536
536
throw error ;
537
537
}
538
538
} else {
539
- isMessageLoopRunning = false ;
539
+ isTaskLoopRunning = false ;
540
540
}
541
541
// Yielding to the browser will give it a chance to paint, so we can
542
542
// reset this.
543
543
needsPaint = false ;
544
544
} ;
545
545
546
- const channel = new MessageChannel ( ) ;
547
- const port = channel . port2 ;
548
- channel . port1 . onmessage = performWorkUntilDeadline ;
546
+ function postTask ( callback ) {
547
+ // Use experimental Chrome Scheduler postTask API.
548
+ global . scheduler . postTask ( callback ) ;
549
+ }
549
550
550
551
function requestHostCallback ( callback ) {
551
- scheduledHostCallback = callback ;
552
- if ( ! isMessageLoopRunning ) {
553
- isMessageLoopRunning = true ;
554
- port . postMessage ( null ) ;
555
- }
556
- }
552
+ scheduledHostCallback = callback ;
553
+ if ( ! isTaskLoopRunning ) {
554
+ isTaskLoopRunning = true ;
555
+ postTask ( performWorkUntilDeadline ) ;
556
+ }
557
+ }
557
558
558
559
function requestHostTimeout ( callback , ms ) {
559
560
taskTimeoutID = setTimeout ( ( ) => {
0 commit comments