Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 76c6ebf

Browse files
authored
feat: allow tasks to be canceled and rescheduled on different zone in a zone delegate (#629)
1) Adds states to the Task: `notScheduled`, `scheduling`, `scheduled`, `running`, `canceling` 2) Adds `cancelScheduleRequest` method to Task. 3) Allows canceling of task scheduling and subsequent re-scheduling from ZoneSpec. This allows a Zone to intercept the scheduling of a Task and redirecting it to another Task.
1 parent f3547cc commit 76c6ebf

4 files changed

Lines changed: 302 additions & 66 deletions

File tree

lib/common/timers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
7171
patchMethod(window, cancelName, (delegate: Function) => function(self: any, args: any[]) {
7272
const task: Task = typeof args[0] === 'number' ? tasksByHandleId[args[0]] : args[0];
7373
if (task && typeof task.type === 'string') {
74-
if (task.cancelFn && task.data.isPeriodic || task.runCount === 0) {
74+
if (task.state !== 'notScheduled' &&
75+
(task.cancelFn && task.data.isPeriodic || task.runCount === 0)) {
7576
// Do not cancel already canceled functions
7677
task.zone.cancelTask(task);
7778
}

0 commit comments

Comments
 (0)