MCPcopy Create free account
hub / github.com/angular/angular / scheduleTask

Method scheduleTask

packages/zone.js/lib/zone-impl.ts:980–1016  ·  view source on GitHub ↗
(task: T)

Source from the content-addressed store, hash-verified

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,

Callers 3

scheduleMicroTaskMethod · 0.95
scheduleMacroTaskMethod · 0.95
scheduleEventTaskMethod · 0.95

Calls 5

_updateTaskCountMethod · 0.95
ErrorInterface · 0.85
_transitionToMethod · 0.80
scheduleTaskMethod · 0.65
handleErrorMethod · 0.65

Tested by

no test coverage detected