Skip to content

Commit c24b641

Browse files
authored
Remove timeout option from scheduleCallback (facebook#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.
1 parent 1442971 commit c24b641

File tree

2 files changed

+20
-49
lines changed

2 files changed

+20
-49
lines changed

packages/scheduler/src/Scheduler.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -276,43 +276,41 @@ function unstable_wrapCallback(callback) {
276276
};
277277
}
278278

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-
295279
function unstable_scheduleCallback(priorityLevel, callback, options) {
296280
var currentTime = getCurrentTime();
297281

298282
var startTime;
299-
var timeout;
300283
if (typeof options === 'object' && options !== null) {
301284
var delay = options.delay;
302285
if (typeof delay === 'number' && delay > 0) {
303286
startTime = currentTime + delay;
304287
} else {
305288
startTime = currentTime;
306289
}
307-
timeout =
308-
typeof options.timeout === 'number'
309-
? options.timeout
310-
: timeoutForPriorityLevel(priorityLevel);
311290
} else {
312-
timeout = timeoutForPriorityLevel(priorityLevel);
313291
startTime = currentTime;
314292
}
315293

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+
316314
var expirationTime = startTime + timeout;
317315

318316
var newTask = {

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -681,33 +681,6 @@ describe('Scheduler', () => {
681681
]);
682682
});
683683

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-
711684
it('cancels a delayed task', () => {
712685
// Schedule several tasks with the same delay
713686
const options = {delay: 100};

0 commit comments

Comments
 (0)