8
8
9
9
/* eslint-disable no-var */
10
10
11
+ import { enableSchedulerDebugging } from 'shared/ReactFeatureFlags' ;
12
+
11
13
// TODO: Use symbols?
12
14
var ImmediatePriority = 1 ;
13
15
var UserBlockingPriority = 2 ;
@@ -33,6 +35,9 @@ var IDLE_PRIORITY = maxSigned31BitInt;
33
35
var firstCallbackNode = null ;
34
36
35
37
var currentDidTimeout = false ;
38
+ // Pausing the scheduler is useful for debugging.
39
+ var isSchedulerPaused = false ;
40
+
36
41
var currentPriorityLevel = NormalPriority ;
37
42
var currentEventStartTime = - 1 ;
38
43
var currentExpirationTime = - 1 ;
@@ -173,13 +178,23 @@ function flushImmediateWork() {
173
178
}
174
179
175
180
function flushWork ( didTimeout ) {
181
+ // Exit right away if we're currently paused
182
+
183
+ if ( enableSchedulerDebugging && isSchedulerPaused ) {
184
+ return ;
185
+ }
186
+
176
187
isExecutingCallback = true ;
177
188
const previousDidTimeout = currentDidTimeout ;
178
189
currentDidTimeout = didTimeout ;
179
190
try {
180
191
if ( didTimeout ) {
181
192
// 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
183
198
// Read the current time. Flush all the callbacks that expire at or
184
199
// earlier than that time. Then read the current time again and repeat.
185
200
// This optimizes for as few performance.now calls as possible.
@@ -189,7 +204,8 @@ function flushWork(didTimeout) {
189
204
flushFirstCallback ( ) ;
190
205
} while (
191
206
firstCallbackNode !== null &&
192
- firstCallbackNode . expirationTime <= currentTime
207
+ firstCallbackNode . expirationTime <= currentTime &&
208
+ ! ( enableSchedulerDebugging && isSchedulerPaused )
193
209
) ;
194
210
continue ;
195
211
}
@@ -199,6 +215,9 @@ function flushWork(didTimeout) {
199
215
// Keep flushing callbacks until we run out of time in the frame.
200
216
if ( firstCallbackNode !== null ) {
201
217
do {
218
+ if ( enableSchedulerDebugging && isSchedulerPaused ) {
219
+ break ;
220
+ }
202
221
flushFirstCallback ( ) ;
203
222
} while ( firstCallbackNode !== null && ! shouldYieldToHost ( ) ) ;
204
223
}
@@ -342,6 +361,21 @@ function unstable_scheduleCallback(callback, deprecated_options) {
342
361
return newNode ;
343
362
}
344
363
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
+
345
379
function unstable_cancelCallback ( callbackNode ) {
346
380
var next = callbackNode . next ;
347
381
if ( next === null ) {
@@ -659,5 +693,8 @@ export {
659
693
unstable_wrapCallback ,
660
694
unstable_getCurrentPriorityLevel ,
661
695
unstable_shouldYield ,
696
+ unstable_continueExecution ,
697
+ unstable_pauseExecution ,
698
+ unstable_getFirstCallbackNode ,
662
699
getCurrentTime as unstable_now ,
663
700
} ;
0 commit comments