@samitouri / QOS-React-2 / commits / c24b641b76

Remove `timeout` option from `scheduleCallback` (#19457)

Since the Lanes refactor landed, we no longer rely on this anywhere, so we can remove it. The `delay` option is still needed by our timer implementation (setTimeout polyfill). We'll keep the feature, but we'll likely change how it's exposed once we figure out the proper layering between the various Scheduler APIs.

Andrew Clark committed Jul 27, 2020 at 11:56 UTC c24b641b768dc6ea2e7303cf0f4436e55ea61964
2 files changed +20 -49
packages/scheduler/src/Scheduler.js
+20 -22
@@ -276,27 +276,10 @@ function unstable_wrapCallback(callback) {
276 };
277 }
278
279 -function timeoutForPriorityLevel(priorityLevel) {
280 - switch (priorityLevel) {
281 - case ImmediatePriority:
282 - return IMMEDIATE_PRIORITY_TIMEOUT;
283 - case UserBlockingPriority:
284 - return USER_BLOCKING_PRIORITY_TIMEOUT;
285 - case IdlePriority:
286 - return IDLE_PRIORITY_TIMEOUT;
287 - case LowPriority:
288 - return LOW_PRIORITY_TIMEOUT;
289 - case NormalPriority:
290 - default:
291 - return NORMAL_PRIORITY_TIMEOUT;
292 - }
293 -}
294 -
279 function unstable_scheduleCallback(priorityLevel, callback, options) {
280 var currentTime = getCurrentTime();
281
282 var startTime;
299 - var timeout;
283 if (typeof options === 'object' && options !== null) {
284 var delay = options.delay;
285 if (typeof delay === 'number' && delay > 0) {
@@ -304,15 +287,30 @@ function unstable_scheduleCallback(priorityLevel, callback, options) {
287 } else {
288 startTime = currentTime;
289 }
307 - timeout =
308 - typeof options.timeout === 'number'
309 - ? options.timeout
310 - : timeoutForPriorityLevel(priorityLevel);
290 } else {
312 - timeout = timeoutForPriorityLevel(priorityLevel);
291 startTime = currentTime;
292 }
293
294 + var timeout;
295 + switch (priorityLevel) {
296 + case ImmediatePriority:
297 + timeout = IMMEDIATE_PRIORITY_TIMEOUT;
298 + break;
299 + case UserBlockingPriority:
300 + timeout = USER_BLOCKING_PRIORITY_TIMEOUT;
301 + break;
302 + case IdlePriority:
303 + timeout = IDLE_PRIORITY_TIMEOUT;
304 + break;
305 + case LowPriority:
306 + timeout = LOW_PRIORITY_TIMEOUT;
307 + break;
308 + case NormalPriority:
309 + default:
310 + timeout = NORMAL_PRIORITY_TIMEOUT;
311 + break;
312 + }
313 +
314 var expirationTime = startTime + timeout;
315
316 var newTask = {
packages/scheduler/src/__tests__/Scheduler-test.js
-27
@@ -681,33 +681,6 @@ describe('Scheduler', () => {
681 ]);
682 });
683
684 - it('schedules callback with both delay and timeout', () => {
685 - scheduleCallback(
686 - NormalPriority,
687 - () => {
688 - Scheduler.unstable_yieldValue('A');
689 - Scheduler.unstable_advanceTime(100);
690 - },
691 - {delay: 100, timeout: 900},
692 - );
693 -
694 - Scheduler.unstable_advanceTime(99);
695 - // Does not flush because delay has not elapsed
696 - expect(Scheduler).toFlushAndYield([]);
697 -
698 - // Delay has elapsed but task has not expired
699 - Scheduler.unstable_advanceTime(1);
700 - expect(Scheduler).toFlushExpired([]);
701 -
702 - // Still not expired
703 - Scheduler.unstable_advanceTime(899);
704 - expect(Scheduler).toFlushExpired([]);
705 -
706 - // Now it expires
707 - Scheduler.unstable_advanceTime(1);
708 - expect(Scheduler).toFlushExpired(['A']);
709 - });
710 -
684 it('cancels a delayed task', () => {
685 // Schedule several tasks with the same delay
686 const options = {delay: 100};