(task: T)
| 978 | } |
| 979 | |
| 980 | scheduleTask<T extends Task>(task: T): T { |
| 981 | if (task.zone && task.zone !== this) { |
| 982 | // check if the task was rescheduled, the newZone |
| 983 | // should not be the children of the original zone |
| 984 | let newZone: any = this; |
| 985 | while (newZone) { |
| 986 | if (newZone === task.zone) { |
| 987 | throw Error( |
| 988 | `can not reschedule task to ${this.name} which is descendants of the original zone ${task.zone.name}`, |
| 989 | ); |
| 990 | } |
| 991 | newZone = newZone.parent; |
| 992 | } |
| 993 | } |
| 994 | (task as any as ZoneTask<any>)._transitionTo(scheduling, notScheduled); |
| 995 | const zoneDelegates: _ZoneDelegate[] = []; |
| 996 | (task as any as ZoneTask<any>)._zoneDelegates = zoneDelegates; |
| 997 | (task as any as ZoneTask<any>)._zone = this; |
| 998 | try { |
| 999 | task = this._zoneDelegate.scheduleTask(this, task) as T; |
| 1000 | } catch (err) { |
| 1001 | // should set task's state to unknown when scheduleTask throw error |
| 1002 | // because the err may from reschedule, so the fromState maybe notScheduled |
| 1003 | (task as any as ZoneTask<any>)._transitionTo(unknown, scheduling, notScheduled); |
| 1004 | // TODO: @JiaLiPassion, should we check the result from handleError? |
| 1005 | this._zoneDelegate.handleError(this, err); |
| 1006 | throw err; |
| 1007 | } |
| 1008 | if ((task as any as ZoneTask<any>)._zoneDelegates === zoneDelegates) { |
| 1009 | // we have to check because internally the delegate can reschedule the task. |
| 1010 | this._updateTaskCount(task as any as ZoneTask<any>, 1); |
| 1011 | } |
| 1012 | if ((task as any as ZoneTask<any>).state == scheduling) { |
| 1013 | (task as any as ZoneTask<any>)._transitionTo(scheduled, scheduling); |
| 1014 | } |
| 1015 | return task; |
| 1016 | } |
| 1017 | |
| 1018 | scheduleMicroTask( |
| 1019 | source: string, |
no test coverage detected