feat: improve IWRR implementation
[poolifier.git] / src / pools / selection-strategies / weighted-round-robin-worker-choice-strategy.ts
index 46575b80d851ec719b783a370d20194b8ba72d58..034c88e6a2a51706d2adf9032dc293794ac6f0e7 100644 (file)
@@ -90,14 +90,13 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
   }
 
   private weightedRoundRobinNextWorkerNodeKey (): number | undefined {
-    const workerVirtualTaskRunTime = this.workerVirtualTaskRunTime
     const workerWeight =
       this.opts.weights?.[
         this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
       ] ?? this.defaultWorkerWeight
-    if (workerVirtualTaskRunTime < workerWeight) {
+    if (this.workerVirtualTaskRunTime < workerWeight) {
       this.workerVirtualTaskRunTime =
-        workerVirtualTaskRunTime +
+        this.workerVirtualTaskRunTime +
         this.getWorkerTaskRunTime(
           this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
         )