build(deps-dev): apply updates
[poolifier.git] / src / pools / selection-strategies / least-busy-worker-choice-strategy.ts
index 8afd2c36edda1bcb7fe94dcb2b6d1f51c36eac9e..31fa281aa75dd0dcbf63fffe1d2508f0277d3f6a 100644 (file)
@@ -12,8 +12,8 @@ import type {
  * Selects the least busy worker.
  *
  * @typeParam Worker - Type of worker which manages the strategy.
- * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
- * @typeParam Response - Type of execution response. This can only be serializable data.
+ * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
+ * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
  */
 export class LeastBusyWorkerChoiceStrategy<
     Worker extends IWorker,
@@ -34,7 +34,11 @@ export class LeastBusyWorkerChoiceStrategy<
       average: false,
       median: false
     },
-    elu: false
+    elu: {
+      aggregate: false,
+      average: false,
+      median: false
+    }
   }
 
   /** @inheritDoc */
@@ -59,19 +63,19 @@ export class LeastBusyWorkerChoiceStrategy<
   /** @inheritDoc */
   public choose (): number {
     let minTime = Infinity
-    let leastBusyWorkerNodeKey!: number
     for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
       const workerTime =
         workerNode.workerUsage.runTime.aggregate +
         workerNode.workerUsage.waitTime.aggregate
       if (workerTime === 0) {
-        return workerNodeKey
+        this.nextWorkerNodeId = workerNodeKey
+        break
       } else if (workerTime < minTime) {
         minTime = workerTime
-        leastBusyWorkerNodeKey = workerNodeKey
+        this.nextWorkerNodeId = workerNodeKey
       }
     }
-    return leastBusyWorkerNodeKey
+    return this.nextWorkerNodeId
   }
 
   /** @inheritDoc */