(task: Task)
| 1056 | } |
| 1057 | |
| 1058 | cancelTask(task: Task): any { |
| 1059 | if (task.zone != this) |
| 1060 | throw new Error( |
| 1061 | 'A task can only be cancelled in the zone of creation! (Creation: ' + |
| 1062 | (task.zone || NO_ZONE).name + |
| 1063 | '; Execution: ' + |
| 1064 | this.name + |
| 1065 | ')', |
| 1066 | ); |
| 1067 | |
| 1068 | if (task.state !== scheduled && task.state !== running) { |
| 1069 | return; |
| 1070 | } |
| 1071 | |
| 1072 | (task as ZoneTask<any>)._transitionTo(canceling, scheduled, running); |
| 1073 | try { |
| 1074 | this._zoneDelegate.cancelTask(this, task); |
| 1075 | } catch (err) { |
| 1076 | // if error occurs when cancelTask, transit the state to unknown |
| 1077 | (task as ZoneTask<any>)._transitionTo(unknown, canceling); |
| 1078 | this._zoneDelegate.handleError(this, err); |
| 1079 | throw err; |
| 1080 | } |
| 1081 | this._updateTaskCount(task as ZoneTask<any>, -1); |
| 1082 | (task as ZoneTask<any>)._transitionTo(notScheduled, canceling); |
| 1083 | task.runCount = -1; |
| 1084 | return task; |
| 1085 | } |
| 1086 | |
| 1087 | private _updateTaskCount(task: ZoneTask<any>, count: number) { |
| 1088 | const zoneDelegates = task._zoneDelegates!; |
nothing calls this directly
no test coverage detected