* Adds a new task that should block application's stability. * @returns A cleanup function that removes a task when called.
()
| 48 | * @returns A cleanup function that removes a task when called. |
| 49 | */ |
| 50 | add(): () => void { |
| 51 | const taskId = this.internalPendingTasks.add(); |
| 52 | return () => { |
| 53 | if (!this.internalPendingTasks.has(taskId)) { |
| 54 | // This pending task has already been cleared. |
| 55 | return; |
| 56 | } |
| 57 | // Notifying the scheduler will hold application stability open until the next tick. |
| 58 | this.scheduler.notify(NotificationSource.PendingTaskRemoved); |
| 59 | this.internalPendingTasks.remove(taskId); |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Runs an asynchronous function and blocks the application's stability until the function completes. |