fix: ensure worker removal impact is propated to worker choice strategy
[poolifier.git] / src / pools / selection-strategies / round-robin-worker-choice-strategy.ts
index e265172fad11beede47047155d360b38c5cff4a0..3880ca391ac4ed980abda24a8740282e750a9b81 100644 (file)
@@ -33,4 +33,15 @@ export class RoundRobinWorkerChoiceStrategy<
         : this.nextWorkerId + 1
     return chosenWorkerKey
   }
+
+  /** {@inheritDoc} */
+  public remove (workerKey: number): boolean {
+    if (this.nextWorkerId === workerKey) {
+      this.nextWorkerId =
+        this.nextWorkerId > this.pool.workers.length - 1
+          ? this.pool.workers.length - 1
+          : this.nextWorkerId
+    }
+    return true
+  }
 }