From 60b7a7ccc07f5ae4931d35ffee48f81b1ddabb7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 25 Aug 2023 18:28:06 +0200 Subject: [PATCH] refactor: remove unneeded condition in task stealing code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/worker-node.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index e28372ef..9ecfd012 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -178,16 +178,14 @@ implements IWorkerNode { } private async startOnEmptyQueue (): Promise { - if (this.onEmptyQueue != null) { - if (this.tasksQueue.size > 0) { - this.onEmptyQueueCount = 0 - return - } - this.onEmptyQueue(this.info.id as number) - ++this.onEmptyQueueCount - await sleep(exponentialDelay(this.onEmptyQueueCount)) - await this.startOnEmptyQueue() + if (this.tasksQueue.size > 0) { + this.onEmptyQueueCount = 0 + return } + (this.onEmptyQueue as (workerId: number) => void)(this.info.id as number) + ++this.onEmptyQueueCount + await sleep(exponentialDelay(this.onEmptyQueueCount)) + await this.startOnEmptyQueue() } private initWorkerInfo (worker: Worker, workerType: WorkerType): WorkerInfo { -- 2.34.1