Skip to content

Commit c9be16f

Browse files
author
Andrew Clark
authored
[scheduler] Rename priority levels (facebook#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_`.
1 parent 3b7ee26 commit c9be16f

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

packages/scheduler/src/Scheduler.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
// TODO: Use symbols?
1212
var ImmediatePriority = 1;
13-
var InteractivePriority = 2;
13+
var UserBlockingPriority = 2;
1414
var NormalPriority = 3;
15-
var WheneverPriority = 4;
15+
var IdlePriority = 4;
1616

1717
// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
1818
// Math.pow(2, 30) - 1
@@ -22,10 +22,10 @@ var maxSigned31BitInt = 1073741823;
2222
// Times out immediately
2323
var IMMEDIATE_PRIORITY_TIMEOUT = -1;
2424
// Eventually times out
25-
var INTERACTIVE_PRIORITY_TIMEOUT = 250;
25+
var USER_BLOCKING_PRIORITY = 250;
2626
var NORMAL_PRIORITY_TIMEOUT = 5000;
2727
// Never times out
28-
var WHENEVER_PRIORITY_TIMEOUT = maxSigned31BitInt;
28+
var IDLE_PRIORITY = maxSigned31BitInt;
2929

3030
// Callbacks are stored as a circular, doubly linked list.
3131
var firstCallbackNode = null;
@@ -254,9 +254,9 @@ function flushWork(didTimeout) {
254254
function unstable_runWithPriority(priorityLevel, eventHandler) {
255255
switch (priorityLevel) {
256256
case ImmediatePriority:
257-
case InteractivePriority:
257+
case UserBlockingPriority:
258258
case NormalPriority:
259-
case WheneverPriority:
259+
case IdlePriority:
260260
break;
261261
default:
262262
priorityLevel = NormalPriority;
@@ -314,11 +314,11 @@ function unstable_scheduleCallback(callback, deprecated_options) {
314314
case ImmediatePriority:
315315
expirationTime = startTime + IMMEDIATE_PRIORITY_TIMEOUT;
316316
break;
317-
case InteractivePriority:
318-
expirationTime = startTime + INTERACTIVE_PRIORITY_TIMEOUT;
317+
case UserBlockingPriority:
318+
expirationTime = startTime + USER_BLOCKING_PRIORITY;
319319
break;
320-
case WheneverPriority:
321-
expirationTime = startTime + WHENEVER_PRIORITY_TIMEOUT;
320+
case IdlePriority:
321+
expirationTime = startTime + IDLE_PRIORITY;
322322
break;
323323
case NormalPriority:
324324
default:
@@ -679,9 +679,9 @@ if (typeof window !== 'undefined' && window._schedMock) {
679679

680680
export {
681681
ImmediatePriority as unstable_ImmediatePriority,
682-
InteractivePriority as unstable_InteractivePriority,
682+
UserBlockingPriority as unstable_UserBlockingPriority,
683683
NormalPriority as unstable_NormalPriority,
684-
WheneverPriority as unstable_WheneverPriority,
684+
IdlePriority as unstable_IdlePriority,
685685
unstable_runWithPriority,
686686
unstable_scheduleCallback,
687687
unstable_cancelCallback,

packages/scheduler/src/__tests__/Scheduler-test.internal.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
let runWithPriority;
1313
let ImmediatePriority;
14-
let InteractivePriority;
14+
let UserBlockingPriority;
1515
let NormalPriority;
1616
let scheduleCallback;
1717
let cancelCallback;
@@ -137,7 +137,7 @@ describe('Scheduler', () => {
137137
const Schedule = require('scheduler');
138138
runWithPriority = Schedule.unstable_runWithPriority;
139139
ImmediatePriority = Schedule.unstable_ImmediatePriority;
140-
InteractivePriority = Schedule.unstable_InteractivePriority;
140+
UserBlockingPriority = Schedule.unstable_UserBlockingPriority;
141141
NormalPriority = Schedule.unstable_NormalPriority;
142142
scheduleCallback = Schedule.unstable_scheduleCallback;
143143
cancelCallback = Schedule.unstable_cancelCallback;
@@ -226,7 +226,7 @@ describe('Scheduler', () => {
226226
// Yield before B is flushed
227227
expect(flushWork(100)).toEqual(['A']);
228228

229-
runWithPriority(InteractivePriority, () => {
229+
runWithPriority(UserBlockingPriority, () => {
230230
scheduleCallback(() => doWork('C', 100));
231231
scheduleCallback(() => doWork('D', 100));
232232
});
@@ -237,11 +237,11 @@ describe('Scheduler', () => {
237237

238238
it('expires work', () => {
239239
scheduleCallback(() => doWork('A', 100));
240-
runWithPriority(InteractivePriority, () => {
240+
runWithPriority(UserBlockingPriority, () => {
241241
scheduleCallback(() => doWork('B', 100));
242242
});
243243
scheduleCallback(() => doWork('C', 100));
244-
runWithPriority(InteractivePriority, () => {
244+
runWithPriority(UserBlockingPriority, () => {
245245
scheduleCallback(() => doWork('D', 100));
246246
});
247247

@@ -314,7 +314,7 @@ describe('Scheduler', () => {
314314
};
315315

316316
// Schedule a high priority callback
317-
runWithPriority(InteractivePriority, () => scheduleCallback(work));
317+
runWithPriority(UserBlockingPriority, () => scheduleCallback(work));
318318

319319
// Flush until just before the expiration time
320320
expect(flushWork(249)).toEqual(['A', 'B', 'Yield!']);
@@ -325,7 +325,7 @@ describe('Scheduler', () => {
325325
});
326326

327327
it('nested callbacks inherit the priority of the currently executing callback', () => {
328-
runWithPriority(InteractivePriority, () => {
328+
runWithPriority(UserBlockingPriority, () => {
329329
scheduleCallback(() => {
330330
doWork('Parent callback', 100);
331331
scheduleCallback(() => {
@@ -336,7 +336,7 @@ describe('Scheduler', () => {
336336

337337
expect(flushWork(100)).toEqual(['Parent callback']);
338338

339-
// The nested callback has interactive priority, so it should
339+
// The nested callback has user-blocking priority, so it should
340340
// expire quickly.
341341
advanceTime(250 + 100);
342342
expect(clearYieldedValues()).toEqual(['Nested callback']);
@@ -360,7 +360,7 @@ describe('Scheduler', () => {
360360
scheduleCallback(work);
361361
expect(flushWork(100)).toEqual(['A', 'Yield!']);
362362

363-
runWithPriority(InteractivePriority, () => {
363+
runWithPriority(UserBlockingPriority, () => {
364364
scheduleCallback(() => doWork('High pri', 100));
365365
});
366366

@@ -379,7 +379,7 @@ describe('Scheduler', () => {
379379
if (task[0] === 'B') {
380380
// Schedule high pri work from inside another callback
381381
yieldValue('Schedule high pri');
382-
runWithPriority(InteractivePriority, () =>
382+
runWithPriority(UserBlockingPriority, () =>
383383
scheduleCallback(() => doWork('High pri', 100)),
384384
);
385385
}
@@ -438,24 +438,24 @@ describe('Scheduler', () => {
438438
});
439439
});
440440
const wrappedInteractiveCallback = runWithPriority(
441-
InteractivePriority,
441+
UserBlockingPriority,
442442
() =>
443443
wrapCallback(() => {
444444
scheduleCallback(() => {
445-
doWork('Interactive', 100);
445+
doWork('User-blocking', 100);
446446
});
447447
}),
448448
);
449449

450450
// This should schedule a normal callback
451451
wrappedCallback();
452-
// This should schedule an interactive callback
452+
// This should schedule an user-blocking callback
453453
wrappedInteractiveCallback();
454454

455455
advanceTime(249);
456456
expect(clearYieldedValues()).toEqual([]);
457457
advanceTime(1);
458-
expect(clearYieldedValues()).toEqual(['Interactive']);
458+
expect(clearYieldedValues()).toEqual(['User-blocking']);
459459

460460
advanceTime(10000);
461461
expect(clearYieldedValues()).toEqual(['Normal']);
@@ -468,26 +468,26 @@ describe('Scheduler', () => {
468468
});
469469
});
470470
const wrappedInteractiveCallback = runWithPriority(
471-
InteractivePriority,
471+
UserBlockingPriority,
472472
() =>
473473
wrapCallback(() => {
474474
scheduleCallback(() => {
475-
doWork('Interactive', 100);
475+
doWork('User-blocking', 100);
476476
});
477477
}),
478478
);
479479

480-
runWithPriority(InteractivePriority, () => {
480+
runWithPriority(UserBlockingPriority, () => {
481481
// This should schedule a normal callback
482482
wrappedCallback();
483-
// This should schedule an interactive callback
483+
// This should schedule an user-blocking callback
484484
wrappedInteractiveCallback();
485485
});
486486

487487
advanceTime(249);
488488
expect(clearYieldedValues()).toEqual([]);
489489
advanceTime(1);
490-
expect(clearYieldedValues()).toEqual(['Interactive']);
490+
expect(clearYieldedValues()).toEqual(['User-blocking']);
491491

492492
advanceTime(10000);
493493
expect(clearYieldedValues()).toEqual(['Normal']);
@@ -536,7 +536,7 @@ describe('Scheduler', () => {
536536
yieldValue(getCurrentPriorityLevel());
537537
runWithPriority(NormalPriority, () => {
538538
yieldValue(getCurrentPriorityLevel());
539-
runWithPriority(InteractivePriority, () => {
539+
runWithPriority(UserBlockingPriority, () => {
540540
yieldValue(getCurrentPriorityLevel());
541541
});
542542
});
@@ -547,7 +547,7 @@ describe('Scheduler', () => {
547547
NormalPriority,
548548
ImmediatePriority,
549549
NormalPriority,
550-
InteractivePriority,
550+
UserBlockingPriority,
551551
ImmediatePriority,
552552
]);
553553
});

packages/scheduler/src/__tests__/SchedulerNoDOM-test.internal.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
let scheduleCallback;
1313
let runWithPriority;
1414
let ImmediatePriority;
15-
let InteractivePriority;
15+
let UserBlockingPriority;
1616

1717
describe('SchedulerNoDOM', () => {
1818
// If Scheduler runs in a non-DOM environment, it falls back to a naive
@@ -27,7 +27,7 @@ describe('SchedulerNoDOM', () => {
2727
scheduleCallback = Scheduler.unstable_scheduleCallback;
2828
runWithPriority = Scheduler.unstable_runWithPriority;
2929
ImmediatePriority = Scheduler.unstable_ImmediatePriority;
30-
InteractivePriority = Scheduler.unstable_InteractivePriority;
30+
UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
3131
});
3232

3333
it('runAllTimers flushes all scheduled callbacks', () => {
@@ -55,7 +55,7 @@ describe('SchedulerNoDOM', () => {
5555
scheduleCallback(() => {
5656
log.push('B');
5757
});
58-
runWithPriority(InteractivePriority, () => {
58+
runWithPriority(UserBlockingPriority, () => {
5959
scheduleCallback(() => {
6060
log.push('C');
6161
});
@@ -78,7 +78,7 @@ describe('SchedulerNoDOM', () => {
7878
scheduleCallback(() => {
7979
log.push('B');
8080
});
81-
runWithPriority(InteractivePriority, () => {
81+
runWithPriority(UserBlockingPriority, () => {
8282
scheduleCallback(() => {
8383
log.push('C');
8484
});

0 commit comments

Comments
 (0)