fix: ensure worker removal impact is propated to worker choice strategy
[poolifier.git] / src / pools / abstract-pool.ts
index 172feda0555cac95e453860ebddda218e5a5755d..095a4f7b99840ff1c0ff9074d6cd66dca2efa1d0 100644 (file)
@@ -260,10 +260,7 @@ export abstract class AbstractPool<
     if (message.error != null) {
       ++workerTasksUsage.error
     }
-    if (
-      this.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .requiredStatistics.runTime
-    ) {
+    if (this.workerChoiceStrategyContext.getRequiredStatistics().runTime) {
       workerTasksUsage.runTime += message.taskRunTime ?? 0
       if (workerTasksUsage.run !== 0) {
         workerTasksUsage.avgRunTime =
@@ -278,7 +275,9 @@ export abstract class AbstractPool<
    * @param worker - The worker that will be removed.
    */
   protected removeWorker (worker: Worker): void {
-    this.workers.splice(this.getWorkerKey(worker), 1)
+    const workerKey = this.getWorkerKey(worker)
+    this.workers.splice(workerKey, 1)
+    this.workerChoiceStrategyContext.remove(workerKey)
   }
 
   /**