feat: allow tasks to be canceled and rescheduled on different zone in…#629
feat: allow tasks to be canceled and rescheduled on different zone in…#629mhevery merged 1 commit intoangular:masterfrom
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. |
| logLevel: config.LOG_INFO, | ||
|
|
||
| browsers: ['Firefox'], | ||
| browsers: ['ChromeCanary'], |
| 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 ) { |
| 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) => |
| scheduleEventTask( | ||
| source: string, callback: Function, data: TaskData, customSchedule: (task: Task) => void, | ||
| customCancel: (task: Task) => void): EventTask; | ||
| scheduleTask<T extends Task>(task: T): T; |
| */ | ||
| runCount: number; | ||
|
|
||
| cancelScheduleRequest(): void; |
|
|
||
| public fork(zoneSpec: ZoneSpec): AmbientZone { | ||
| if (!zoneSpec) throw new Error('ZoneSpec required!'); | ||
| if (!zoneSpec) throw Error('ZoneSpec required!'); |
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