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