From 7b56f532ef66ecf7adefe979100c0d26f95245d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 16 Jun 2023 12:54:59 +0200 Subject: [PATCH] refactor: simplify condition MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 4 ++++ src/pools/abstract-pool.ts | 17 ++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8466e2ba..9058bed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ensure no tasks are queued when trying to soft kill a dynamic worker. +### Changed + +- Optimize O(1) queue implementation. + ## [2.6.2] - 2023-06-12 ### Fixed diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 21cfb395..ac4cb31e 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -720,15 +720,14 @@ export abstract class AbstractPool< const currentWorkerNodeKey = this.getWorkerNodeKey(worker) if ( isKillBehavior(KillBehaviors.HARD, message.kill) || - (this.opts.enableTasksQueue === false && - message.kill != null && - this.workerNodes[currentWorkerNodeKey].workerUsage.tasks.executing === - 0) || - (this.opts.enableTasksQueue === true && - message.kill != null && - this.workerNodes[currentWorkerNodeKey].workerUsage.tasks.executing === - 0 && - this.tasksQueueSize(currentWorkerNodeKey) === 0) + (message.kill != null && + ((this.opts.enableTasksQueue === false && + this.workerNodes[currentWorkerNodeKey].workerUsage.tasks + .executing === 0) || + (this.opts.enableTasksQueue === true && + this.workerNodes[currentWorkerNodeKey].workerUsage.tasks + .executing === 0 && + this.tasksQueueSize(currentWorkerNodeKey) === 0))) ) { // Kill message received from the worker: no new tasks are submitted to that worker for a while ( > maxInactiveTime) void (this.destroyWorker(worker) as Promise) -- 2.34.1