88
99/* eslint-disable no-var */
1010
11+ import { enableSchedulerDebugging } from 'shared/ReactFeatureFlags' ;
12+
1113// TODO: Use symbols?
1214var ImmediatePriority = 1 ;
1315var UserBlockingPriority = 2 ;
@@ -33,6 +35,9 @@ var IDLE_PRIORITY = maxSigned31BitInt;
3335var firstCallbackNode = null ;
3436
3537var currentDidTimeout = false ;
38+ // Pausing the scheduler is useful for debugging.
39+ var isSchedulerPaused = false ;
40+
3641var currentPriorityLevel = NormalPriority ;
3742var currentEventStartTime = - 1 ;
3843var currentExpirationTime = - 1 ;
@@ -173,13 +178,23 @@ function flushImmediateWork() {
173178}
174179
175180function flushWork ( didTimeout ) {
181+ // Exit right away if we're currently paused
182+
183+ if ( enableSchedulerDebugging && isSchedulerPaused ) {
184+ return ;
185+ }
186+
176187 isExecutingCallback = true ;
177188 const previousDidTimeout = currentDidTimeout ;
178189 currentDidTimeout = didTimeout ;
179190 try {
180191 if ( didTimeout ) {
181192 // Flush all the expired callbacks without yielding.
182- while ( firstCallbackNode !== null ) {
193+ while (
194+ firstCallbackNode !== null &&
195+ ! ( enableSchedulerDebugging && isSchedulerPaused )
196+ ) {
197+ // TODO Wrap i nfeature flag
183198 // Read the current time. Flush all the callbacks that expire at or
184199 // earlier than that time. Then read the current time again and repeat.
185200 // This optimizes for as few performance.now calls as possible.
@@ -189,7 +204,8 @@ function flushWork(didTimeout) {
189204 flushFirstCallback ( ) ;
190205 } while (
191206 firstCallbackNode !== null &&
192- firstCallbackNode . expirationTime <= currentTime
207+ firstCallbackNode . expirationTime <= currentTime &&
208+ ! ( enableSchedulerDebugging && isSchedulerPaused )
193209 ) ;
194210 continue ;
195211 }
@@ -199,6 +215,9 @@ function flushWork(didTimeout) {
199215 // Keep flushing callbacks until we run out of time in the frame.
200216 if ( firstCallbackNode !== null ) {
201217 do {
218+ if ( enableSchedulerDebugging && isSchedulerPaused ) {
219+ break ;
220+ }
202221 flushFirstCallback ( ) ;
203222 } while ( firstCallbackNode !== null && ! shouldYieldToHost ( ) ) ;
204223 }
@@ -342,6 +361,21 @@ function unstable_scheduleCallback(callback, deprecated_options) {
342361 return newNode ;
343362}
344363
364+ function unstable_pauseExecution ( ) {
365+ isSchedulerPaused = true ;
366+ }
367+
368+ function unstable_continueExecution ( ) {
369+ isSchedulerPaused = false ;
370+ if ( firstCallbackNode !== null ) {
371+ ensureHostCallbackIsScheduled ( ) ;
372+ }
373+ }
374+
375+ function unstable_getFirstCallbackNode ( ) {
376+ return firstCallbackNode ;
377+ }
378+
345379function unstable_cancelCallback ( callbackNode ) {
346380 var next = callbackNode . next ;
347381 if ( next === null ) {
@@ -659,5 +693,8 @@ export {
659693 unstable_wrapCallback ,
660694 unstable_getCurrentPriorityLevel ,
661695 unstable_shouldYield ,
696+ unstable_continueExecution ,
697+ unstable_pauseExecution ,
698+ unstable_getFirstCallbackNode ,
662699 getCurrentTime as unstable_now ,
663700} ;
0 commit comments