X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fworker-choice-strategy-context.ts;h=5e9f7de9dce24e1510e52d68c09bfb6486df1f52;hb=d29bce7c35c0be75535b4d1eb0f22ef38b3f8204;hp=34aa332e39677883c066c9bd823276e8e56e886c;hpb=c4855468bc26a7ee37d2c8ef34bb1ac864448e77;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 34aa332e..5e9f7de9 100644 --- a/src/pools/selection-strategies/worker-choice-strategy-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategy-context.ts @@ -19,7 +19,7 @@ import { WeightedRoundRobinWorkerChoiceStrategy } from './weighted-round-robin-w * * @typeParam Worker - Type of worker. * @typeParam Data - Type of data sent to the worker. This can only be serializable data. - * @typeParam Response - Type of response of execution. This can only be serializable data. + * @typeParam Response - Type of execution response. This can only be serializable data. */ export class WorkerChoiceStrategyContext< Worker extends IWorker, @@ -35,12 +35,12 @@ export class WorkerChoiceStrategyContext< * Worker choice strategy context constructor. * * @param pool - The pool instance. - * @param workerChoiceStrategyType - The worker choice strategy. + * @param workerChoiceStrategy - The worker choice strategy. * @param opts - The worker choice strategy options. */ public constructor ( pool: IPool, - private workerChoiceStrategyType: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN, + private workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN, opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS ) { this.execute.bind(this) @@ -82,7 +82,7 @@ export class WorkerChoiceStrategyContext< public getRequiredStatistics (): RequiredStatistics { return ( this.workerChoiceStrategies.get( - this.workerChoiceStrategyType + this.workerChoiceStrategy ) as IWorkerChoiceStrategy ).requiredStatistics } @@ -95,10 +95,10 @@ export class WorkerChoiceStrategyContext< public setWorkerChoiceStrategy ( workerChoiceStrategy: WorkerChoiceStrategy ): void { - if (this.workerChoiceStrategyType !== workerChoiceStrategy) { - this.workerChoiceStrategyType = workerChoiceStrategy + if (this.workerChoiceStrategy !== workerChoiceStrategy) { + this.workerChoiceStrategy = workerChoiceStrategy } - this.workerChoiceStrategies.get(this.workerChoiceStrategyType)?.reset() + this.workerChoiceStrategies.get(this.workerChoiceStrategy)?.reset() } /** @@ -109,7 +109,7 @@ export class WorkerChoiceStrategyContext< public execute (): number { return ( this.workerChoiceStrategies.get( - this.workerChoiceStrategyType + this.workerChoiceStrategy ) as IWorkerChoiceStrategy ).choose() } @@ -123,8 +123,19 @@ export class WorkerChoiceStrategyContext< public remove (workerNodeKey: number): boolean { return ( this.workerChoiceStrategies.get( - this.workerChoiceStrategyType + this.workerChoiceStrategy ) as IWorkerChoiceStrategy ).remove(workerNodeKey) } + + /** + * Sets the worker choice strategies in the context options. + * + * @param opts - The worker choice strategy options. + */ + public setOptions (opts: WorkerChoiceStrategyOptions): void { + this.workerChoiceStrategies.forEach(workerChoiceStrategy => { + workerChoiceStrategy.setOptions(opts) + }) + } }