X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fround-robin-worker-choice-strategy.ts;h=1499db945f8297181724db968f21b938d8f3618b;hb=bf90656cacf88d2cfdd5b3262086ba55b2ff9818;hp=e265172fad11beede47047155d360b38c5cff4a0;hpb=c923ce5670eeae4194aa996d44a1071e88cb21ad;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 e265172f..1499db94 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -1,5 +1,6 @@ import type { IPoolWorker } from '../pool-worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import type { IWorkerChoiceStrategy } from './selection-strategies-types' /** * Selects the next worker in a round robin fashion. @@ -9,10 +10,12 @@ import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' * @typeParam Response - Type of response of execution. This can only be serializable data. */ export class RoundRobinWorkerChoiceStrategy< - Worker extends IPoolWorker, - Data, - Response -> extends AbstractWorkerChoiceStrategy { + Worker extends IPoolWorker, + Data, + Response + > + extends AbstractWorkerChoiceStrategy + implements IWorkerChoiceStrategy { /** * Id of the next worker. */ @@ -33,4 +36,15 @@ export class RoundRobinWorkerChoiceStrategy< : this.nextWorkerId + 1 return chosenWorkerKey } + + /** {@inheritDoc} */ + public remove (workerKey: number): boolean { + if (this.nextWorkerId === workerKey) { + this.nextWorkerId = + this.nextWorkerId > this.pool.workers.length - 1 + ? this.pool.workers.length - 1 + : this.nextWorkerId + } + return true + } }