MCPcopy
hub / github.com/sindresorhus/p-queue / clear

Method clear

source/index.ts:616–645  ·  view source on GitHub ↗

Clear the queue.

()

Source from the content-addressed store, hash-verified

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.

Callers 4

advanced.tsFile · 0.80
basic.tsFile · 0.80
strict.tsFile · 0.80
validation.tsFile · 0.80

Calls 3

#clearIntervalTimerMethod · 0.95
#updateRateLimitStateMethod · 0.95
#clearTimeoutTimerMethod · 0.95

Tested by

no test coverage detected