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

Method run

packages/core/src/pending_tasks.ts:78–94  ·  view source on GitHub ↗

* Runs an asynchronous function and blocks the application's stability until the function completes. * * ```ts * pendingTasks.run(async () => { * const userData = await fetch('/api/user'); * this.userData.set(userData); * }); * ``` * * @param fn The asynchronous functi

(fn: () => Promise<unknown>)

Source from the content-addressed store, hash-verified

76 * @developerPreview 19.0
77 */
78 run(fn: () => Promise<unknown>): void {
79 const removeTask = this.add();
80 try {
81 fn()
82 .catch((err) => {
83 if (!this.destroyRef.destroyed) {
84 this.errorHandler(err);
85 }
86 })
87 .finally(removeTask);
88 } catch (err) {
89 if (!this.destroyRef.destroyed) {
90 this.errorHandler(err);
91 }
92 removeTask();
93 }
94 }
95
96 /** @nocollapse */
97 static ɵprov = /** @pureOrBreakMyCode */ /* @__PURE__ */ ɵɵdefineInjectable({

Callers

nothing calls this directly

Calls 4

addMethod · 0.95
finallyMethod · 0.80
fnFunction · 0.50
catchMethod · 0.45

Tested by

no test coverage detected