* 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<Worker, Data, Response>,
- private workerChoiceStrategyType: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN,
+ private workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN,
opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
this.execute.bind(this)
public getRequiredStatistics (): RequiredStatistics {
return (
this.workerChoiceStrategies.get(
- this.workerChoiceStrategyType
+ this.workerChoiceStrategy
) as IWorkerChoiceStrategy
).requiredStatistics
}
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()
}
/**
public execute (): number {
return (
this.workerChoiceStrategies.get(
- this.workerChoiceStrategyType
+ this.workerChoiceStrategy
) as IWorkerChoiceStrategy
).choose()
}
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)
+ })
+ }
}