@returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`. If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item. Note that this only limits the number of items waiting to star
(limit: number)
| 666 | Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation. |
| 667 | */ |
| 668 | async onSizeLessThan(limit: number): Promise<void> { |
| 669 | // Instantly resolve if the queue is empty. |
| 670 | if (this.#queue.size < limit) { |
| 671 | return; |
| 672 | } |
| 673 | |
| 674 | await this.#onEvent('next', () => this.#queue.size < limit); |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet. |