()
| 53 | } |
| 54 | |
| 55 | async #execNext() { |
| 56 | if (this.#mode === "linear" && this.#busy) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | const task = this.#queue.shift(); |
| 61 | if (!task) return; |
| 62 | |
| 63 | let result; |
| 64 | let error; |
| 65 | |
| 66 | try { |
| 67 | this.#busy = true; |
| 68 | const id = this.#count++; |
| 69 | result = await task(id); |
| 70 | } catch (err) { |
| 71 | error = err; |
| 72 | } finally { |
| 73 | this.#busy = false; |
| 74 | } |
| 75 | |
| 76 | this.#listeners.forEach((l) => l(task, result, error)); |
| 77 | if (this.#mode === "linear") this.#execNext(); |
| 78 | } |
| 79 | } |