MCPcopy
hub / github.com/sindresorhus/p-queue / #tryToStartAnother

Method #tryToStartAnother

source/index.ts:289–338  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

287 }
288
289 #tryToStartAnother(): boolean {
290 if (this.#queue.size === 0) {
291 // We can clear the interval ("pause")
292 // Because we can redo it later ("resume")
293 this.#clearIntervalTimer();
294 this.emit('empty');
295
296 if (this.#pending === 0) {
297 // Clear timeout as well when completely idle
298 this.#clearTimeoutTimer();
299
300 // Compact strict ticks when idle to free memory
301 if (this.#strict && this.#strictTicksStartIndex > 0) {
302 const now = Date.now();
303 this.#cleanupStrictTicks(now);
304 }
305
306 this.emit('idle');
307 }
308
309 return false;
310 }
311
312 let taskStarted = false;
313
314 if (!this.#isPaused) {
315 const now = Date.now();
316 const canInitializeInterval = !this.#isIntervalPausedAt(now);
317
318 if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) {
319 const job = this.#queue.dequeue()!;
320
321 if (!this.#isIntervalIgnored) {
322 this.#consumeIntervalSlot(now);
323 this.#scheduleRateLimitUpdate();
324 }
325
326 this.emit('active');
327 job();
328
329 if (canInitializeInterval) {
330 this.#initializeIntervalIfNeeded();
331 }
332
333 taskStarted = true;
334 }
335 }
336
337 return taskStarted;
338 }
339
340 #initializeIntervalIfNeeded(): void {
341 if (this.#isIntervalIgnored || this.#intervalId !== undefined) {

Callers 4

#nextMethod · 0.95
#processQueueMethod · 0.95
queueAbortHandlerMethod · 0.95
addMethod · 0.95

Calls 8

#clearIntervalTimerMethod · 0.95
#clearTimeoutTimerMethod · 0.95
#cleanupStrictTicksMethod · 0.95
#isIntervalPausedAtMethod · 0.95
#consumeIntervalSlotMethod · 0.95
dequeueMethod · 0.80

Tested by

no test coverage detected