chore: v3.1.9
[poolifier.git] / src / pools / selection-strategies / round-robin-worker-choice-strategy.ts
index 19dd3872c116723756fb146a4a57506b10523ab0..2d08cff20621ba564bb0b424c32a4bcd904f53bb 100644 (file)
@@ -1,10 +1,9 @@
-import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
 import type { IPool } from '../pool'
 import type { IWorker } from '../worker'
 import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
 import type {
   IWorkerChoiceStrategy,
-  WorkerChoiceStrategyOptions
+  InternalWorkerChoiceStrategyOptions
 } from './selection-strategies-types'
 
 /**
@@ -24,10 +23,9 @@ export class RoundRobinWorkerChoiceStrategy<
   /** @inheritDoc */
   public constructor (
     pool: IPool<Worker, Data, Response>,
-    opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+    opts: InternalWorkerChoiceStrategyOptions
   ) {
     super(pool, opts)
-    this.setTaskStatisticsRequirements(this.opts)
   }
 
   /** @inheritDoc */
@@ -46,6 +44,7 @@ export class RoundRobinWorkerChoiceStrategy<
     const chosenWorkerNodeKey = this.nextWorkerNodeKey
     this.setPreviousWorkerNodeKey(chosenWorkerNodeKey)
     this.roundRobinNextWorkerNodeKey()
+    this.checkNextWorkerNodeReadiness()
     return chosenWorkerNodeKey
   }
 
@@ -70,12 +69,10 @@ export class RoundRobinWorkerChoiceStrategy<
   }
 
   private roundRobinNextWorkerNodeKey (): number | undefined {
-    do {
-      this.nextWorkerNodeKey =
-        this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
-          ? 0
-          : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
-    } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey))
+    this.nextWorkerNodeKey =
+      this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
+        ? 0
+        : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
     return this.nextWorkerNodeKey
   }
 }