Skip to content

Commit

Permalink
[Scheduler] Bugfix: Cancelling a continuation
Browse files Browse the repository at this point in the history
Cancelling the original task should also cancel its continuation.
  • Loading branch information
acdlite committed Jul 17, 2019
1 parent d9b4c55 commit b22cf43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/scheduler/src/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,8 @@ function flushTask(task, currentTime) {
// with the same priority and expiration as the just-finished callback.
if (typeof continuationCallback === 'function') {
var expirationTime = task.expirationTime;
var continuationTask = {
callback: continuationCallback,
priorityLevel: task.priorityLevel,
startTime: task.startTime,
expirationTime,
next: null,
previous: null,
};
var continuationTask = task;
continuationTask.callback = continuationCallback;

// Insert the new callback into the list, sorted by its timeout. This is
// almost the same as the code in `scheduleCallback`, except the callback
Expand Down
13 changes: 13 additions & 0 deletions packages/scheduler/src/__tests__/Scheduler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ describe('Scheduler', () => {
},
);

it('cancelling a continuation', () => {
const task = scheduleCallback(NormalPriority, () => {
Scheduler.unstable_yieldValue('Yield');
return () => {
Scheduler.unstable_yieldValue('Continuation');
};
});

expect(Scheduler).toFlushAndYieldThrough(['Yield']);
cancelCallback(task);
expect(Scheduler).toFlushWithoutYielding();
});

it('top-level immediate callbacks fire in a subsequent task', () => {
scheduleCallback(ImmediatePriority, () =>
Scheduler.unstable_yieldValue('A'),
Expand Down

0 comments on commit b22cf43

Please sign in to comment.