[scheduler] Rename priority levels (#13842)
- "Interactive" -> "user-blocking" - "Whenever" -> "Idle" These are the terms used by @spanicker in their main-thread scheduling proposal: https://github.com/spanicker/main-thread-scheduling#api-sketch That proposal also uses "microtask" instead of "immediate" and "default" instead of "normal." Not sure about "microtask" because I don't think most people know what that is. And our implementation isn't a proper microtask, though you could use it to implement microtasks if you made sure to wrap every entry point. I don't really have a preference between "default" and "normal." These aren't necessarily the final names. Still prefixed by `unstable_`.
Andrew Clark committed
Oct 12, 2018 at 14:42 UTC
c9be16f5b6fc85e1458467a0c1e9743b15549424
3 files changed
+37
-37
packages/scheduler/src/Scheduler.js
+12
-12
@@ -10,9 +10,9 @@
10
11
// TODO: Use symbols?
12
var ImmediatePriority = 1;
13
-var InteractivePriority = 2;
13
+var UserBlockingPriority = 2;
14
var NormalPriority = 3;
15
-var WheneverPriority = 4;
15
+var IdlePriority = 4;
16
17
// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
18
// Math.pow(2, 30) - 1
@@ -22,10 +22,10 @@ var maxSigned31BitInt = 1073741823;
22
// Times out immediately
23
var IMMEDIATE_PRIORITY_TIMEOUT = -1;
24
// Eventually times out
25
-var INTERACTIVE_PRIORITY_TIMEOUT = 250;
25
+var USER_BLOCKING_PRIORITY = 250;
26
var NORMAL_PRIORITY_TIMEOUT = 5000;
27
// Never times out
28
-var WHENEVER_PRIORITY_TIMEOUT = maxSigned31BitInt;
28
+var IDLE_PRIORITY = maxSigned31BitInt;
29
30
// Callbacks are stored as a circular, doubly linked list.
31
var firstCallbackNode = null;
@@ -254,9 +254,9 @@ function flushWork(didTimeout) {
254
function unstable_runWithPriority(priorityLevel, eventHandler) {
255
switch (priorityLevel) {
256
case ImmediatePriority:
257
- case InteractivePriority:
257
+ case UserBlockingPriority:
258
case NormalPriority:
259
- case WheneverPriority:
259
+ case IdlePriority:
260
break;
261
default:
262
priorityLevel = NormalPriority;
@@ -314,11 +314,11 @@ function unstable_scheduleCallback(callback, deprecated_options) {
314
case ImmediatePriority:
315
expirationTime = startTime + IMMEDIATE_PRIORITY_TIMEOUT;
316
break;
317
- case InteractivePriority:
318
- expirationTime = startTime + INTERACTIVE_PRIORITY_TIMEOUT;
317
+ case UserBlockingPriority:
318
+ expirationTime = startTime + USER_BLOCKING_PRIORITY;
319
break;
320
- case WheneverPriority:
321
- expirationTime = startTime + WHENEVER_PRIORITY_TIMEOUT;
320
+ case IdlePriority:
321
+ expirationTime = startTime + IDLE_PRIORITY;
322
break;
323
case NormalPriority:
324
default:
@@ -679,9 +679,9 @@ if (typeof window !== 'undefined' && window._schedMock) {
679
680
export {
681
ImmediatePriority as unstable_ImmediatePriority,
682
- InteractivePriority as unstable_InteractivePriority,
682
+ UserBlockingPriority as unstable_UserBlockingPriority,
683
NormalPriority as unstable_NormalPriority,
684
- WheneverPriority as unstable_WheneverPriority,
684
+ IdlePriority as unstable_IdlePriority,
685
unstable_runWithPriority,
686
unstable_scheduleCallback,
687
unstable_cancelCallback,
packages/scheduler/src/__tests__/Scheduler-test.internal.js
+21
-21
@@ -11,7 +11,7 @@
11
12
let runWithPriority;
13
let ImmediatePriority;
14
-let InteractivePriority;
14
+let UserBlockingPriority;
15
let NormalPriority;
16
let scheduleCallback;
17
let cancelCallback;
@@ -137,7 +137,7 @@ describe('Scheduler', () => {
137
const Schedule = require('scheduler');
138
runWithPriority = Schedule.unstable_runWithPriority;
139
ImmediatePriority = Schedule.unstable_ImmediatePriority;
140
- InteractivePriority = Schedule.unstable_InteractivePriority;
140
+ UserBlockingPriority = Schedule.unstable_UserBlockingPriority;
141
NormalPriority = Schedule.unstable_NormalPriority;
142
scheduleCallback = Schedule.unstable_scheduleCallback;
143
cancelCallback = Schedule.unstable_cancelCallback;
@@ -226,7 +226,7 @@ describe('Scheduler', () => {
226
// Yield before B is flushed
227
expect(flushWork(100)).toEqual(['A']);
228
229
- runWithPriority(InteractivePriority, () => {
229
+ runWithPriority(UserBlockingPriority, () => {
230
scheduleCallback(() => doWork('C', 100));
231
scheduleCallback(() => doWork('D', 100));
232
});
@@ -237,11 +237,11 @@ describe('Scheduler', () => {
237
238
it('expires work', () => {
239
scheduleCallback(() => doWork('A', 100));
240
- runWithPriority(InteractivePriority, () => {
240
+ runWithPriority(UserBlockingPriority, () => {
241
scheduleCallback(() => doWork('B', 100));
242
});
243
scheduleCallback(() => doWork('C', 100));
244
- runWithPriority(InteractivePriority, () => {
244
+ runWithPriority(UserBlockingPriority, () => {
245
scheduleCallback(() => doWork('D', 100));
246
});
247
@@ -314,7 +314,7 @@ describe('Scheduler', () => {
314
};
315
316
// Schedule a high priority callback
317
- runWithPriority(InteractivePriority, () => scheduleCallback(work));
317
+ runWithPriority(UserBlockingPriority, () => scheduleCallback(work));
318
319
// Flush until just before the expiration time
320
expect(flushWork(249)).toEqual(['A', 'B', 'Yield!']);
@@ -325,7 +325,7 @@ describe('Scheduler', () => {
325
});
326
327
it('nested callbacks inherit the priority of the currently executing callback', () => {
328
- runWithPriority(InteractivePriority, () => {
328
+ runWithPriority(UserBlockingPriority, () => {
329
scheduleCallback(() => {
330
doWork('Parent callback', 100);
331
scheduleCallback(() => {
@@ -336,7 +336,7 @@ describe('Scheduler', () => {
336
337
expect(flushWork(100)).toEqual(['Parent callback']);
338
339
- // The nested callback has interactive priority, so it should
339
+ // The nested callback has user-blocking priority, so it should
340
// expire quickly.
341
advanceTime(250 + 100);
342
expect(clearYieldedValues()).toEqual(['Nested callback']);
@@ -360,7 +360,7 @@ describe('Scheduler', () => {
360
scheduleCallback(work);
361
expect(flushWork(100)).toEqual(['A', 'Yield!']);
362
363
- runWithPriority(InteractivePriority, () => {
363
+ runWithPriority(UserBlockingPriority, () => {
364
scheduleCallback(() => doWork('High pri', 100));
365
});
366
@@ -379,7 +379,7 @@ describe('Scheduler', () => {
379
if (task[0] === 'B') {
380
// Schedule high pri work from inside another callback
381
yieldValue('Schedule high pri');
382
- runWithPriority(InteractivePriority, () =>
382
+ runWithPriority(UserBlockingPriority, () =>
383
scheduleCallback(() => doWork('High pri', 100)),
384
);
385
}
@@ -438,24 +438,24 @@ describe('Scheduler', () => {
438
});
439
});
440
const wrappedInteractiveCallback = runWithPriority(
441
- InteractivePriority,
441
+ UserBlockingPriority,
442
() =>
443
wrapCallback(() => {
444
scheduleCallback(() => {
445
- doWork('Interactive', 100);
445
+ doWork('User-blocking', 100);
446
});
447
}),
448
);
449
450
// This should schedule a normal callback
451
wrappedCallback();
452
- // This should schedule an interactive callback
452
+ // This should schedule an user-blocking callback
453
wrappedInteractiveCallback();
454
455
advanceTime(249);
456
expect(clearYieldedValues()).toEqual([]);
457
advanceTime(1);
458
- expect(clearYieldedValues()).toEqual(['Interactive']);
458
+ expect(clearYieldedValues()).toEqual(['User-blocking']);
459
460
advanceTime(10000);
461
expect(clearYieldedValues()).toEqual(['Normal']);
@@ -468,26 +468,26 @@ describe('Scheduler', () => {
468
});
469
});
470
const wrappedInteractiveCallback = runWithPriority(
471
- InteractivePriority,
471
+ UserBlockingPriority,
472
() =>
473
wrapCallback(() => {
474
scheduleCallback(() => {
475
- doWork('Interactive', 100);
475
+ doWork('User-blocking', 100);
476
});
477
}),
478
);
479
480
- runWithPriority(InteractivePriority, () => {
480
+ runWithPriority(UserBlockingPriority, () => {
481
// This should schedule a normal callback
482
wrappedCallback();
483
- // This should schedule an interactive callback
483
+ // This should schedule an user-blocking callback
484
wrappedInteractiveCallback();
485
});
486
487
advanceTime(249);
488
expect(clearYieldedValues()).toEqual([]);
489
advanceTime(1);
490
- expect(clearYieldedValues()).toEqual(['Interactive']);
490
+ expect(clearYieldedValues()).toEqual(['User-blocking']);
491
492
advanceTime(10000);
493
expect(clearYieldedValues()).toEqual(['Normal']);
@@ -536,7 +536,7 @@ describe('Scheduler', () => {
536
yieldValue(getCurrentPriorityLevel());
537
runWithPriority(NormalPriority, () => {
538
yieldValue(getCurrentPriorityLevel());
539
- runWithPriority(InteractivePriority, () => {
539
+ runWithPriority(UserBlockingPriority, () => {
540
yieldValue(getCurrentPriorityLevel());
541
});
542
});
@@ -547,7 +547,7 @@ describe('Scheduler', () => {
547
NormalPriority,
548
ImmediatePriority,
549
NormalPriority,
550
- InteractivePriority,
550
+ UserBlockingPriority,
551
ImmediatePriority,
552
]);
553
});
packages/scheduler/src/__tests__/SchedulerNoDOM-test.internal.js
+4
-4
@@ -12,7 +12,7 @@
12
let scheduleCallback;
13
let runWithPriority;
14
let ImmediatePriority;
15
-let InteractivePriority;
15
+let UserBlockingPriority;
16
17
describe('SchedulerNoDOM', () => {
18
// If Scheduler runs in a non-DOM environment, it falls back to a naive
@@ -27,7 +27,7 @@ describe('SchedulerNoDOM', () => {
27
scheduleCallback = Scheduler.unstable_scheduleCallback;
28
runWithPriority = Scheduler.unstable_runWithPriority;
29
ImmediatePriority = Scheduler.unstable_ImmediatePriority;
30
- InteractivePriority = Scheduler.unstable_InteractivePriority;
30
+ UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
31
});
32
33
it('runAllTimers flushes all scheduled callbacks', () => {
@@ -55,7 +55,7 @@ describe('SchedulerNoDOM', () => {
55
scheduleCallback(() => {
56
log.push('B');
57
});
58
- runWithPriority(InteractivePriority, () => {
58
+ runWithPriority(UserBlockingPriority, () => {
59
scheduleCallback(() => {
60
log.push('C');
61
});
@@ -78,7 +78,7 @@ describe('SchedulerNoDOM', () => {
78
scheduleCallback(() => {
79
log.push('B');
80
});
81
- runWithPriority(InteractivePriority, () => {
81
+ runWithPriority(UserBlockingPriority, () => {
82
scheduleCallback(() => {
83
log.push('C');
84
});