X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fround-robin-worker-choice-strategy.ts;h=29b05fa507f0b3ca8a18a300ad1c6927d9b76a65;hb=7cd8af0033b35def46016a78ea9be1ee516480bf;hp=9b49d7643581d8a4991bc1b25239b2053e0265d2;hpb=b2b1d84ebeb8299fda9b6090c9951e953749bbe0;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 9b49d764..29b05fa5 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -15,19 +15,19 @@ export class RoundRobinWorkerChoiceStrategy< Response = unknown > extends AbstractWorkerChoiceStrategy - implements IWorkerChoiceStrategy { + implements IWorkerChoiceStrategy { /** * Id of the next worker. */ private nextWorkerId: number = 0 - /** {@inheritDoc} */ + /** @inheritDoc */ public reset (): boolean { this.nextWorkerId = 0 return true } - /** {@inheritDoc} */ + /** @inheritDoc */ public choose (): number { const chosenWorkerKey = this.nextWorkerId this.nextWorkerId = @@ -37,13 +37,17 @@ export class RoundRobinWorkerChoiceStrategy< return chosenWorkerKey } - /** {@inheritDoc} */ + /** @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 + if (this.pool.workers.length === 0) { + this.nextWorkerId = 0 + } else { + this.nextWorkerId = + this.nextWorkerId > this.pool.workers.length - 1 + ? this.pool.workers.length - 1 + : this.nextWorkerId + } } return true }