X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fworker-choice-strategy-context.ts;h=e3aaaea36c4fbfaf628d4d1bea31c64bfbb0d6a3;hb=8c0b113f317f5e59160fb5174fd951330756221b;hp=fefc1275f5cb7fbacf72d689dfaf8140a733ffac;hpb=4ba8492f17b13668853cfc15a1ec9ff8c8d7b179;p=poolifier.git diff --git a/src/pools/selection-strategies/worker-choice-strategy-context.ts b/src/pools/selection-strategies/worker-choice-strategy-context.ts index fefc1275..e3aaaea3 100644 --- a/src/pools/selection-strategies/worker-choice-strategy-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategy-context.ts @@ -37,7 +37,7 @@ export class WorkerChoiceStrategyContext< /** * The number of times the worker choice strategy in the context has been retried. */ - private choiceRetriesCount = 0 + private retriesCount = 0 /** * Worker choice strategy context constructor. @@ -168,7 +168,7 @@ export class WorkerChoiceStrategyContext< * Executes the worker choice strategy in the context algorithm. * * @returns The key of the worker node. - * @throws {@link https://nodejs.org/api/errors.html#class-error} If the worker node key is null or undefined. + * @throws {@link https://nodejs.org/api/errors.html#class-error} If after configured retries the worker node key is null or undefined . */ public execute (): number { const workerNodeKey = ( @@ -178,15 +178,16 @@ export class WorkerChoiceStrategyContext< ).choose() if ( workerNodeKey == null && - this.choiceRetriesCount < (this.opts.choiceRetries as number) + this.retriesCount < (this.opts.retries as number) ) { - this.choiceRetriesCount++ + this.retriesCount++ return this.execute() } else if (workerNodeKey == null) { - throw new TypeError( - `Worker node key chosen is null or undefined after ${this.choiceRetriesCount} retries` + throw new Error( + `Worker node key chosen is null or undefined after ${this.retriesCount} retries` ) } + this.retriesCount = 0 return workerNodeKey }