(task: Task, applyThis?: any, applyArgs?: any)
| 918 | } |
| 919 | |
| 920 | runTask(task: Task, applyThis?: any, applyArgs?: any): any { |
| 921 | if (task.zone != this) { |
| 922 | throw new Error( |
| 923 | 'A task can only be run in the zone of creation! (Creation: ' + |
| 924 | (task.zone || NO_ZONE).name + |
| 925 | '; Execution: ' + |
| 926 | this.name + |
| 927 | ')', |
| 928 | ); |
| 929 | } |
| 930 | |
| 931 | const zoneTask = task as ZoneTask<any>; |
| 932 | // https://github.com/angular/zone.js/issues/778, sometimes eventTask |
| 933 | // will run in notScheduled(canceled) state, we should not try to |
| 934 | // run such kind of task but just return |
| 935 | const {type, data: {isPeriodic = false, isRefreshable = false} = {}} = task; |
| 936 | |
| 937 | if (task.state === notScheduled && (type === eventTask || type === macroTask)) { |
| 938 | return; |
| 939 | } |
| 940 | |
| 941 | const reEntryGuard = task.state != running; |
| 942 | reEntryGuard && zoneTask._transitionTo(running, scheduled); |
| 943 | const previousTask = _currentTask; |
| 944 | _currentTask = zoneTask; |
| 945 | _currentZoneFrame = {parent: _currentZoneFrame, zone: this}; |
| 946 | |
| 947 | try { |
| 948 | if (type == macroTask && task.data && !isPeriodic && !isRefreshable) { |
| 949 | task.cancelFn = undefined; |
| 950 | } |
| 951 | try { |
| 952 | return this._zoneDelegate.invokeTask(this, zoneTask, applyThis, applyArgs); |
| 953 | } catch (error) { |
| 954 | if (this._zoneDelegate.handleError(this, error)) { |
| 955 | throw error; |
| 956 | } |
| 957 | } |
| 958 | } finally { |
| 959 | // if the task's state is notScheduled or unknown, then it has already been cancelled |
| 960 | // we should not reset the state to scheduled |
| 961 | const state = task.state; |
| 962 | if (state !== notScheduled && state !== unknown) { |
| 963 | if (type == eventTask || isPeriodic || (isRefreshable && state === scheduling)) { |
| 964 | reEntryGuard && zoneTask._transitionTo(scheduled, running, scheduling); |
| 965 | } else { |
| 966 | const zoneDelegates = zoneTask._zoneDelegates; |
| 967 | this._updateTaskCount(zoneTask, -1); |
| 968 | reEntryGuard && zoneTask._transitionTo(notScheduled, running, notScheduled); |
| 969 | |
| 970 | if (isRefreshable) { |
| 971 | zoneTask._zoneDelegates = zoneDelegates; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | _currentZoneFrame = _currentZoneFrame.parent!; |
| 976 | _currentTask = previousTask; |
| 977 | } |
nothing calls this directly
no test coverage detected