Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove timeout option from scheduleCallback #19457

Merged
merged 1 commit into from Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 20 additions & 22 deletions packages/scheduler/src/Scheduler.js
Expand Up @@ -276,43 +276,41 @@ function unstable_wrapCallback(callback) {
};
}

function timeoutForPriorityLevel(priorityLevel) {
switch (priorityLevel) {
case ImmediatePriority:
return IMMEDIATE_PRIORITY_TIMEOUT;
case UserBlockingPriority:
return USER_BLOCKING_PRIORITY_TIMEOUT;
case IdlePriority:
return IDLE_PRIORITY_TIMEOUT;
case LowPriority:
return LOW_PRIORITY_TIMEOUT;
case NormalPriority:
default:
return NORMAL_PRIORITY_TIMEOUT;
}
}

function unstable_scheduleCallback(priorityLevel, callback, options) {
var currentTime = getCurrentTime();

var startTime;
var timeout;
if (typeof options === 'object' && options !== null) {
var delay = options.delay;
if (typeof delay === 'number' && delay > 0) {
startTime = currentTime + delay;
} else {
startTime = currentTime;
}
timeout =
typeof options.timeout === 'number'
? options.timeout
: timeoutForPriorityLevel(priorityLevel);
} else {
timeout = timeoutForPriorityLevel(priorityLevel);
startTime = currentTime;
}

var timeout;
switch (priorityLevel) {
case ImmediatePriority:
timeout = IMMEDIATE_PRIORITY_TIMEOUT;
break;
case UserBlockingPriority:
timeout = USER_BLOCKING_PRIORITY_TIMEOUT;
break;
case IdlePriority:
timeout = IDLE_PRIORITY_TIMEOUT;
break;
case LowPriority:
timeout = LOW_PRIORITY_TIMEOUT;
break;
case NormalPriority:
default:
timeout = NORMAL_PRIORITY_TIMEOUT;
break;
}

var expirationTime = startTime + timeout;

var newTask = {
Expand Down
27 changes: 0 additions & 27 deletions packages/scheduler/src/__tests__/Scheduler-test.js
Expand Up @@ -681,33 +681,6 @@ describe('Scheduler', () => {
]);
});

it('schedules callback with both delay and timeout', () => {
scheduleCallback(
NormalPriority,
() => {
Scheduler.unstable_yieldValue('A');
Scheduler.unstable_advanceTime(100);
},
{delay: 100, timeout: 900},
);

Scheduler.unstable_advanceTime(99);
// Does not flush because delay has not elapsed
expect(Scheduler).toFlushAndYield([]);

// Delay has elapsed but task has not expired
Scheduler.unstable_advanceTime(1);
expect(Scheduler).toFlushExpired([]);

// Still not expired
Scheduler.unstable_advanceTime(899);
expect(Scheduler).toFlushExpired([]);

// Now it expires
Scheduler.unstable_advanceTime(1);
expect(Scheduler).toFlushExpired(['A']);
});

it('cancels a delayed task', () => {
// Schedule several tasks with the same delay
const options = {delay: 100};
Expand Down