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

Method dequeue

source/priority-queue.ts:82–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

80 }
81
82 dequeue(): RunFunction | undefined {
83 if (this.#head === this.#queue.length) {
84 return undefined;
85 }
86
87 const item = this.#queue[this.#head];
88 this.#head++;
89
90 if (this.#head === this.#queue.length) {
91 // Fully drained queues are reset immediately so the next enqueue starts from a clean array.
92 this.#queue.length = 0;
93 this.#head = 0;
94 } else if (this.#head > compactionThreshold && this.#head > this.#queue.length / 2) {
95 // Keep repeated dequeues cheap, but stop the consumed prefix from growing without bound.
96 this.#compact();
97 }
98
99 return item?.run;
100 }
101
102 filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[] {
103 const result: RunFunction[] = [];

Callers 3

bench.tsFile · 0.80
#tryToStartAnotherMethod · 0.80
priority-queue.tsFile · 0.80

Calls 1

#compactMethod · 0.95

Tested by

no test coverage detected