-
Notifications
You must be signed in to change notification settings - Fork 408
feat: allow tasks to be canceled and rescheduled on different zone in… #629
Conversation
TODO
|
@mhevery, could you explain a little more about the motivation of this PR, I would like to learn more deeply about it. in the commit message, you said that the feature is 'allow tasks to be canceled and rescheduled on different zone', I don't understand when we need to do that. thank you very much. |
cff7b67
to
0db62e9
Compare
@JiaLiPassion sorry for the delayed response. The issue can best be described by this test Imagine that you want to write a ZoneSpec which would redirect the scheduling of a task to a different zone. For example you want to make sure that all In addition it was hard to keep track of in which state the task was, so I made the Task state explicit, which helps with the error messages. |
karma-base.conf.js
Outdated
@@ -39,7 +39,7 @@ module.exports = function (config) { | |||
|
|||
logLevel: config.LOG_INFO, | |||
|
|||
browsers: ['Firefox'], | |||
browsers: ['ChromeCanary'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
lib/common/timers.ts
Outdated
@@ -71,8 +71,8 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam | |||
patchMethod(window, cancelName, (delegate: Function) => function(self: any, args: any[]) { | |||
const task: Task = typeof args[0] === 'number' ? tasksByHandleId[args[0]] : args[0]; | |||
if (task && typeof task.type === 'string') { | |||
if (task.cancelFn && task.data.isPeriodic || task.runCount === 0) { | |||
// Do not cancel already canceled functions | |||
if (task.state !== 'notScheduled' && task.cancelFn ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
lib/common/utils.ts
Outdated
target: any, name: string, | ||
patchFn: (delegate: Function, delegateName: string, name: string) => (self: any, args: any[]) => | ||
any): Function { | ||
target: any, name: string, patchFn: (delegate: Function, delegateName: string, name: string) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
lib/zone.ts
Outdated
@@ -229,6 +229,7 @@ interface Zone { | |||
scheduleEventTask( | |||
source: string, callback: Function, data: TaskData, customSchedule: (task: Task) => void, | |||
customCancel: (task: Task) => void): EventTask; | |||
scheduleTask<T extends Task>(task: T): T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add docs
lib/zone.ts
Outdated
@@ -516,6 +527,8 @@ interface Task { | |||
* Number of times the task has been executed, or -1 if canceled. | |||
*/ | |||
runCount: number; | |||
|
|||
cancelScheduleRequest(): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add docs
lib/zone.ts
Outdated
@@ -622,13 +639,13 @@ const Zone: ZoneType = (function(global: any) { | |||
} | |||
|
|||
public fork(zoneSpec: ZoneSpec): AmbientZone { | |||
if (!zoneSpec) throw new Error('ZoneSpec required!'); | |||
if (!zoneSpec) throw Error('ZoneSpec required!'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
87b5350
to
60db4f2
Compare
… a zone delegate 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.
@mhevery , Thank you for explaining, I will read the source and learn how it works! |
… a zone delegate