refactor: simplify condition
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 16 Jun 2023 10:54:59 +0000 (12:54 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 16 Jun 2023 10:54:59 +0000 (12:54 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
CHANGELOG.md
src/pools/abstract-pool.ts

index 8466e2baab4542741f54fae07909f2205c52c385..9058bed670386b13d551213ac93b50187b5597be 100644 (file)
@@ -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
index 21cfb395785cdc14a82987498b85236b4295c8dd..ac4cb31ed4576bcce9fea5dbab191e1bc11c103b 100644 (file)
@@ -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<void>)