MCPcopy
hub / github.com/angular/angular / runTask

Method runTask

packages/zone.js/lib/zone-impl.ts:925–983  ·  view source on GitHub ↗
(task: Task, applyThis?: any, applyArgs?: any)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

_updateTaskCountMethod · 0.95
_transitionToMethod · 0.80
invokeTaskMethod · 0.65
handleErrorMethod · 0.65

Tested by

no test coverage detected