Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it desirable to mutate task.callback, task.next and task.previous? if not, the task object needs to be copied, not simply assigned.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's on purpose.

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