* 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>)
| 74 | * @developerPreview 19.0 |
| 75 | */ |
| 76 | run(fn: () => Promise<unknown>): void { |
| 77 | const removeTask = this.add(); |
| 78 | try { |
| 79 | fn().catch(this.errorHandler).finally(removeTask); |
| 80 | } catch (err) { |
| 81 | this.errorHandler(err); |
| 82 | removeTask(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** @nocollapse */ |
| 87 | static ɵprov = /** @pureOrBreakMyCode */ /* @__PURE__ */ ɵɵdefineInjectable({ |