build(deps): bump poolifier
[poolifier.git] / src / pools / selection-strategies / interleaved-weighted-round-robin-worker-choice-strategy.ts
index e5370428409c337be5b81772eacf5f80a03576f1..e37543820593a68b6860e7b597c40919c8866e9d 100644 (file)
@@ -4,7 +4,6 @@ import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
 import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
 import type {
   IWorkerChoiceStrategy,
-  StrategyPolicy,
   WorkerChoiceStrategyOptions
 } from './selection-strategies-types'
 
@@ -22,12 +21,6 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
   >
   extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
   implements IWorkerChoiceStrategy {
-  /** @inheritDoc */
-  public readonly strategyPolicy: StrategyPolicy = {
-    dynamicWorkerUsage: false,
-    dynamicWorkerReady: true
-  }
-
   /**
    * Round id.
    * This is used to determine the current round weight.
@@ -55,7 +48,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public reset (): boolean {
-    this.nextWorkerNodeKey = 0
+    this.resetWorkerNodeKeyProperties()
     this.roundId = 0
     return true
   }
@@ -67,7 +60,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public choose (): number | undefined {
-    let roundId: number = this.roundId
+    let roundId!: number
     let workerNodeId: number | undefined
     for (
       let roundIndex = this.roundId;
@@ -81,12 +74,12 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
         workerNodeKey < this.pool.workerNodes.length;
         workerNodeKey++
       ) {
+        if (!this.isWorkerNodeEligible(workerNodeKey)) {
+          continue
+        }
         const workerWeight =
           this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight
-        if (
-          this.isWorkerNodeEligible(workerNodeKey) &&
-          workerWeight >= this.roundWeights[roundIndex]
-        ) {
+        if (workerWeight >= this.roundWeights[roundIndex]) {
           workerNodeId = workerNodeKey
           break
         }