From 04fd9c3c8b38ee979de848f76003048e4f346a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Grimnes?= Date: Thu, 15 Jul 2021 13:32:35 +0200 Subject: [PATCH] fix!: remove size property and replace it with getSize() BREAKING CHANGE: replaced the parameter `size` with the getter function `getSize()` --- lib/PromiseQueue.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/PromiseQueue.ts b/lib/PromiseQueue.ts index f278941..473f079 100644 --- a/lib/PromiseQueue.ts +++ b/lib/PromiseQueue.ts @@ -12,7 +12,7 @@ export class PromiseQueue extends EventEmitter implements StrictEmitter void }> { /** Number of tasks currently in the queue and awaiting completion. */ - size = 0; + #size = 0; /** Flag indicating the queue is currently processing tasks. */ #paused = false; /** Number of tasks currently being executed. */ @@ -51,7 +51,7 @@ export class PromiseQueue extends EventEmitter implements StrictEmitter { try { if ( - this.#paused || this.#inflight >= this.concurrency || this.size === 0 + this.#paused || this.#inflight >= this.concurrency || this.#size === 0 ) { return; } @@ -59,13 +59,13 @@ export class PromiseQueue extends EventEmitter implements StrictEmitter entries.length); - assert(priorityIndex >= 0, `Expected the queue to contain entries since the queue size is: ${this.size}`); + assert(priorityIndex >= 0, `Expected the queue to contain entries since the queue size is: ${this.#size}`); this.#inflight += 1; const nextTask = this.#bucketQueue?.[priorityIndex]?.shift() as BucketQueueEntry; - this.size -= 1; + this.#size -= 1; assert(nextTask, "Expected the item list to contain an entry since findIndex() returned != -1"); @@ -102,6 +102,11 @@ export class PromiseQueue extends EventEmitter implements StrictEmitter { this.#bucketQueue[priority].push({ task, resolve, reject }); - this.size += 1; // total queue size. Decreased within the async iterator. + this.#size += 1; // total queue size. Decreased within the async iterator. this.#emitter.emit("new-task"); });