Skip to content

Commit

Permalink
[scheduler] Rename priority levels (#13842)
Browse files Browse the repository at this point in the history
- "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_`.
  • Loading branch information
Andrew Clark authored Oct 12, 2018
1 parent 3b7ee26 commit c9be16f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
24 changes: 12 additions & 12 deletions packages/scheduler/src/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

// TODO: Use symbols?
var ImmediatePriority = 1;
var InteractivePriority = 2;
var UserBlockingPriority = 2;
var NormalPriority = 3;
var WheneverPriority = 4;
var IdlePriority = 4;

// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
// Math.pow(2, 30) - 1
Expand All @@ -22,10 +22,10 @@ var maxSigned31BitInt = 1073741823;
// Times out immediately
var IMMEDIATE_PRIORITY_TIMEOUT = -1;
// Eventually times out
var INTERACTIVE_PRIORITY_TIMEOUT = 250;
var USER_BLOCKING_PRIORITY = 250;
var NORMAL_PRIORITY_TIMEOUT = 5000;
// Never times out
var WHENEVER_PRIORITY_TIMEOUT = maxSigned31BitInt;
var IDLE_PRIORITY = maxSigned31BitInt;

// Callbacks are stored as a circular, doubly linked list.
var firstCallbackNode = null;
Expand Down Expand Up @@ -254,9 +254,9 @@ function flushWork(didTimeout) {
function unstable_runWithPriority(priorityLevel, eventHandler) {
switch (priorityLevel) {
case ImmediatePriority:
case InteractivePriority:
case UserBlockingPriority:
case NormalPriority:
case WheneverPriority:
case IdlePriority:
break;
default:
priorityLevel = NormalPriority;
Expand Down Expand Up @@ -314,11 +314,11 @@ function unstable_scheduleCallback(callback, deprecated_options) {
case ImmediatePriority:
expirationTime = startTime + IMMEDIATE_PRIORITY_TIMEOUT;
break;
case InteractivePriority:
expirationTime = startTime + INTERACTIVE_PRIORITY_TIMEOUT;
case UserBlockingPriority:
expirationTime = startTime + USER_BLOCKING_PRIORITY;
break;
case WheneverPriority:
expirationTime = startTime + WHENEVER_PRIORITY_TIMEOUT;
case IdlePriority:
expirationTime = startTime + IDLE_PRIORITY;
break;
case NormalPriority:
default:
Expand Down Expand Up @@ -679,9 +679,9 @@ if (typeof window !== 'undefined' && window._schedMock) {

export {
ImmediatePriority as unstable_ImmediatePriority,
InteractivePriority as unstable_InteractivePriority,
UserBlockingPriority as unstable_UserBlockingPriority,
NormalPriority as unstable_NormalPriority,
WheneverPriority as unstable_WheneverPriority,
IdlePriority as unstable_IdlePriority,
unstable_runWithPriority,
unstable_scheduleCallback,
unstable_cancelCallback,
Expand Down
42 changes: 21 additions & 21 deletions packages/scheduler/src/__tests__/Scheduler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

let runWithPriority;
let ImmediatePriority;
let InteractivePriority;
let UserBlockingPriority;
let NormalPriority;
let scheduleCallback;
let cancelCallback;
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('Scheduler', () => {
const Schedule = require('scheduler');
runWithPriority = Schedule.unstable_runWithPriority;
ImmediatePriority = Schedule.unstable_ImmediatePriority;
InteractivePriority = Schedule.unstable_InteractivePriority;
UserBlockingPriority = Schedule.unstable_UserBlockingPriority;
NormalPriority = Schedule.unstable_NormalPriority;
scheduleCallback = Schedule.unstable_scheduleCallback;
cancelCallback = Schedule.unstable_cancelCallback;
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('Scheduler', () => {
// Yield before B is flushed
expect(flushWork(100)).toEqual(['A']);

runWithPriority(InteractivePriority, () => {
runWithPriority(UserBlockingPriority, () => {
scheduleCallback(() => doWork('C', 100));
scheduleCallback(() => doWork('D', 100));
});
Expand All @@ -237,11 +237,11 @@ describe('Scheduler', () => {

it('expires work', () => {
scheduleCallback(() => doWork('A', 100));
runWithPriority(InteractivePriority, () => {
runWithPriority(UserBlockingPriority, () => {
scheduleCallback(() => doWork('B', 100));
});
scheduleCallback(() => doWork('C', 100));
runWithPriority(InteractivePriority, () => {
runWithPriority(UserBlockingPriority, () => {
scheduleCallback(() => doWork('D', 100));
});

Expand Down Expand Up @@ -314,7 +314,7 @@ describe('Scheduler', () => {
};

// Schedule a high priority callback
runWithPriority(InteractivePriority, () => scheduleCallback(work));
runWithPriority(UserBlockingPriority, () => scheduleCallback(work));

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

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

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

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

runWithPriority(InteractivePriority, () => {
runWithPriority(UserBlockingPriority, () => {
scheduleCallback(() => doWork('High pri', 100));
});

Expand All @@ -379,7 +379,7 @@ describe('Scheduler', () => {
if (task[0] === 'B') {
// Schedule high pri work from inside another callback
yieldValue('Schedule high pri');
runWithPriority(InteractivePriority, () =>
runWithPriority(UserBlockingPriority, () =>
scheduleCallback(() => doWork('High pri', 100)),
);
}
Expand Down Expand Up @@ -438,24 +438,24 @@ describe('Scheduler', () => {
});
});
const wrappedInteractiveCallback = runWithPriority(
InteractivePriority,
UserBlockingPriority,
() =>
wrapCallback(() => {
scheduleCallback(() => {
doWork('Interactive', 100);
doWork('User-blocking', 100);
});
}),
);

// This should schedule a normal callback
wrappedCallback();
// This should schedule an interactive callback
// This should schedule an user-blocking callback
wrappedInteractiveCallback();

advanceTime(249);
expect(clearYieldedValues()).toEqual([]);
advanceTime(1);
expect(clearYieldedValues()).toEqual(['Interactive']);
expect(clearYieldedValues()).toEqual(['User-blocking']);

advanceTime(10000);
expect(clearYieldedValues()).toEqual(['Normal']);
Expand All @@ -468,26 +468,26 @@ describe('Scheduler', () => {
});
});
const wrappedInteractiveCallback = runWithPriority(
InteractivePriority,
UserBlockingPriority,
() =>
wrapCallback(() => {
scheduleCallback(() => {
doWork('Interactive', 100);
doWork('User-blocking', 100);
});
}),
);

runWithPriority(InteractivePriority, () => {
runWithPriority(UserBlockingPriority, () => {
// This should schedule a normal callback
wrappedCallback();
// This should schedule an interactive callback
// This should schedule an user-blocking callback
wrappedInteractiveCallback();
});

advanceTime(249);
expect(clearYieldedValues()).toEqual([]);
advanceTime(1);
expect(clearYieldedValues()).toEqual(['Interactive']);
expect(clearYieldedValues()).toEqual(['User-blocking']);

advanceTime(10000);
expect(clearYieldedValues()).toEqual(['Normal']);
Expand Down Expand Up @@ -536,7 +536,7 @@ describe('Scheduler', () => {
yieldValue(getCurrentPriorityLevel());
runWithPriority(NormalPriority, () => {
yieldValue(getCurrentPriorityLevel());
runWithPriority(InteractivePriority, () => {
runWithPriority(UserBlockingPriority, () => {
yieldValue(getCurrentPriorityLevel());
});
});
Expand All @@ -547,7 +547,7 @@ describe('Scheduler', () => {
NormalPriority,
ImmediatePriority,
NormalPriority,
InteractivePriority,
UserBlockingPriority,
ImmediatePriority,
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let scheduleCallback;
let runWithPriority;
let ImmediatePriority;
let InteractivePriority;
let UserBlockingPriority;

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

it('runAllTimers flushes all scheduled callbacks', () => {
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('SchedulerNoDOM', () => {
scheduleCallback(() => {
log.push('B');
});
runWithPriority(InteractivePriority, () => {
runWithPriority(UserBlockingPriority, () => {
scheduleCallback(() => {
log.push('C');
});
Expand All @@ -78,7 +78,7 @@ describe('SchedulerNoDOM', () => {
scheduleCallback(() => {
log.push('B');
});
runWithPriority(InteractivePriority, () => {
runWithPriority(UserBlockingPriority, () => {
scheduleCallback(() => {
log.push('C');
});
Expand Down

0 comments on commit c9be16f

Please sign in to comment.