Clear the queue.
()
| 614 | Clear the queue. |
| 615 | */ |
| 616 | clear(): void { |
| 617 | for (const cleanupQueueAbortHandler of this.#queueAbortListenerCleanupFunctions) { |
| 618 | cleanupQueueAbortHandler(); |
| 619 | } |
| 620 | |
| 621 | this.#queue = new this.#queueClass(); |
| 622 | |
| 623 | // Clear interval timer since queue is now empty (consistent with #tryToStartAnother) |
| 624 | this.#clearIntervalTimer(); |
| 625 | |
| 626 | // Note: We preserve strict mode rate-limiting state (ticks and timeout) |
| 627 | // because clear() only clears queued tasks, not rate limit history. |
| 628 | // This ensures that rate limits are still enforced after clearing the queue. |
| 629 | |
| 630 | // Note: We don't clear #runningTasks as those tasks are still running |
| 631 | // They will be removed when they complete in the finally block |
| 632 | |
| 633 | // Force synchronous update since clear() should have immediate effect |
| 634 | this.#updateRateLimitState(); |
| 635 | |
| 636 | // Emit events so waiters (onEmpty, onIdle, onSizeLessThan) can resolve |
| 637 | this.emit('empty'); |
| 638 | |
| 639 | if (this.#pending === 0) { |
| 640 | this.#clearTimeoutTimer(); |
| 641 | this.emit('idle'); |
| 642 | } |
| 643 | |
| 644 | this.emit('next'); |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | Can be called multiple times. Useful if you for example add additional items at a later time. |
no test coverage detected