* 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>)
| 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({ |