From c9be16f5b6fc85e1458467a0c1e9743b15549424 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Fri, 12 Oct 2018 14:42:15 -0700 Subject: [PATCH] [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_`. --- packages/scheduler/src/Scheduler.js | 24 +++++------ .../src/__tests__/Scheduler-test.internal.js | 42 +++++++++---------- .../__tests__/SchedulerNoDOM-test.internal.js | 8 ++-- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/packages/scheduler/src/Scheduler.js b/packages/scheduler/src/Scheduler.js index d52babaa1c541..07c8f779e8884 100644 --- a/packages/scheduler/src/Scheduler.js +++ b/packages/scheduler/src/Scheduler.js @@ -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 @@ -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; @@ -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; @@ -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: @@ -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, diff --git a/packages/scheduler/src/__tests__/Scheduler-test.internal.js b/packages/scheduler/src/__tests__/Scheduler-test.internal.js index 7b5a66859b8d9..8337621a50bd9 100644 --- a/packages/scheduler/src/__tests__/Scheduler-test.internal.js +++ b/packages/scheduler/src/__tests__/Scheduler-test.internal.js @@ -11,7 +11,7 @@ let runWithPriority; let ImmediatePriority; -let InteractivePriority; +let UserBlockingPriority; let NormalPriority; let scheduleCallback; let cancelCallback; @@ -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; @@ -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)); }); @@ -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)); }); @@ -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!']); @@ -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(() => { @@ -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']); @@ -360,7 +360,7 @@ describe('Scheduler', () => { scheduleCallback(work); expect(flushWork(100)).toEqual(['A', 'Yield!']); - runWithPriority(InteractivePriority, () => { + runWithPriority(UserBlockingPriority, () => { scheduleCallback(() => doWork('High pri', 100)); }); @@ -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)), ); } @@ -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']); @@ -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']); @@ -536,7 +536,7 @@ describe('Scheduler', () => { yieldValue(getCurrentPriorityLevel()); runWithPriority(NormalPriority, () => { yieldValue(getCurrentPriorityLevel()); - runWithPriority(InteractivePriority, () => { + runWithPriority(UserBlockingPriority, () => { yieldValue(getCurrentPriorityLevel()); }); }); @@ -547,7 +547,7 @@ describe('Scheduler', () => { NormalPriority, ImmediatePriority, NormalPriority, - InteractivePriority, + UserBlockingPriority, ImmediatePriority, ]); }); diff --git a/packages/scheduler/src/__tests__/SchedulerNoDOM-test.internal.js b/packages/scheduler/src/__tests__/SchedulerNoDOM-test.internal.js index 88f4a0eae509f..5a66ec0d6972f 100644 --- a/packages/scheduler/src/__tests__/SchedulerNoDOM-test.internal.js +++ b/packages/scheduler/src/__tests__/SchedulerNoDOM-test.internal.js @@ -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 @@ -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', () => { @@ -55,7 +55,7 @@ describe('SchedulerNoDOM', () => { scheduleCallback(() => { log.push('B'); }); - runWithPriority(InteractivePriority, () => { + runWithPriority(UserBlockingPriority, () => { scheduleCallback(() => { log.push('C'); }); @@ -78,7 +78,7 @@ describe('SchedulerNoDOM', () => { scheduleCallback(() => { log.push('B'); }); - runWithPriority(InteractivePriority, () => { + runWithPriority(UserBlockingPriority, () => { scheduleCallback(() => { log.push('C'); });