X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fround-robin-worker-choice-strategy.ts;h=be4fe3326b9585c8bd4f7261023cda4fe5af710e;hb=de037b034ea2cbc5530d45dd24685fde95a66155;hp=80e958a406fa2209ce1c20eded5b8e9b79e9ca0b;hpb=027063571693f211b35c8851566a063201adb9af;p=poolifier.git diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index 80e958a4..be4fe332 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -1,6 +1,11 @@ +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 } from './selection-strategies-types' +import type { + IWorkerChoiceStrategy, + WorkerChoiceStrategyOptions +} from './selection-strategies-types' /** * Selects the next worker in a round robin fashion. @@ -21,12 +26,26 @@ export class RoundRobinWorkerChoiceStrategy< */ private nextWorkerNodeId: number = 0 + /** @inheritDoc */ + public constructor ( + pool: IPool, + opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS + ) { + super(pool, opts) + this.setRequiredStatistics(this.opts) + } + /** @inheritDoc */ public reset (): boolean { this.nextWorkerNodeId = 0 return true } + /** @inheritDoc */ + public update (): boolean { + return true + } + /** @inheritDoc */ public choose (): number { const chosenWorkerNodeKey = this.nextWorkerNodeId @@ -42,11 +61,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