docs: refine benchmarks README
[poolifier.git] / src / pools / selection-strategies / round-robin-worker-choice-strategy.ts
index 5e35636af62e77d5b56720344c14c274a0c0a97e..936925313f99e9bafa6c3bb8c0a71f7ad0c94fad 100644 (file)
@@ -4,6 +4,7 @@ import type { IWorker } from '../worker'
 import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
 import type {
   IWorkerChoiceStrategy,
+  StrategyPolicy,
   WorkerChoiceStrategyOptions
 } from './selection-strategies-types'
 
@@ -21,6 +22,11 @@ export class RoundRobinWorkerChoiceStrategy<
   >
   extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
   implements IWorkerChoiceStrategy {
+  /** @inheritDoc */
+  public readonly strategyPolicy: StrategyPolicy = {
+    useDynamicWorker: true
+  }
+
   /**
    * Id of the next worker node.
    */
@@ -32,7 +38,7 @@ export class RoundRobinWorkerChoiceStrategy<
     opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
   ) {
     super(pool, opts)
-    this.checkOptions(this.opts)
+    this.setTaskStatisticsRequirements(this.opts)
   }
 
   /** @inheritDoc */
@@ -61,11 +67,8 @@ export class RoundRobinWorkerChoiceStrategy<
     if (this.nextWorkerNodeId === workerNodeKey) {
       if (this.pool.workerNodes.length === 0) {
         this.nextWorkerNodeId = 0
-      } else {
-        this.nextWorkerNodeId =
-          this.nextWorkerNodeId > this.pool.workerNodes.length - 1
-            ? this.pool.workerNodes.length - 1
-            : this.nextWorkerNodeId
+      } else if (this.nextWorkerNodeId > this.pool.workerNodes.length - 1) {
+        this.nextWorkerNodeId = this.pool.workerNodes.length - 1
       }
     }
     return true