* Adds a task to the queue and returns a promise that resolves with the task's result. * * Enqueues a task for sequential execution. The task will be executed after all * previously queued tasks have completed. If a timeout was specified in the constructor, * there will be a delay between th
(task: () => T)
| 117 | * ``` |
| 118 | */ |
| 119 | async push<T>(task: () => T): Promise<Awaited<T>> { |
| 120 | return new Promise<Awaited<T>>((resolve, reject) => { |
| 121 | this.queue.push(() => Promise.resolve(task()).then(resolve).catch(reject)) |
| 122 | this.run() |
| 123 | }) |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Clears all pending tasks from the queue. |