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