chore: v2.4.0-1
[poolifier.git] / src / pools / selection-strategies / less-busy-worker-choice-strategy.ts
index 769f3fb6b5626eed0841a1b6acf86f7d3ebe0bcd..f2e401625ddd3764cd646d5cd931d23415f5f648 100644 (file)
@@ -25,20 +25,23 @@ export class LessBusyWorkerChoiceStrategy<
   }
 
   /** {@inheritDoc} */
-  public choose (): Worker {
+  public choose (): number {
     let minRunTime = Infinity
-    let lessBusyWorker!: Worker
-    for (const value of this.pool.workers.values()) {
-      const worker = value.worker
-      const workerRunTime = this.pool.getWorkerTasksUsage(worker)
-        ?.runTime as number
+    let lessBusyWorkerKey!: number
+    for (const [index, workerItem] of this.pool.workers.entries()) {
+      const workerRunTime = workerItem.tasksUsage.runTime
       if (!this.isDynamicPool && workerRunTime === 0) {
-        return worker
+        return index
       } else if (workerRunTime < minRunTime) {
         minRunTime = workerRunTime
-        lessBusyWorker = worker
+        lessBusyWorkerKey = index
       }
     }
-    return lessBusyWorker
+    return lessBusyWorkerKey
+  }
+
+  /** {@inheritDoc} */
+  public remove (workerKey: number): boolean {
+    return true
   }
 }