+ this.opts = { ...DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS, ...opts }
+ this.execute = this.execute.bind(this)
+ this.workerChoiceStrategies = new Map<
+ WorkerChoiceStrategy,
+ IWorkerChoiceStrategy
+ >([
+ [
+ WorkerChoiceStrategies.ROUND_ROBIN,
+ new (RoundRobinWorkerChoiceStrategy.bind(this))<Worker, Data, Response>(
+ pool,
+ opts
+ )
+ ],
+ [
+ WorkerChoiceStrategies.LEAST_USED,
+ new (LeastUsedWorkerChoiceStrategy.bind(this))<Worker, Data, Response>(
+ pool,
+ opts
+ )
+ ],
+ [
+ WorkerChoiceStrategies.LEAST_BUSY,
+ new (LeastBusyWorkerChoiceStrategy.bind(this))<Worker, Data, Response>(
+ pool,
+ opts
+ )
+ ],
+ [
+ WorkerChoiceStrategies.LEAST_ELU,
+ new (LeastEluWorkerChoiceStrategy.bind(this))<Worker, Data, Response>(
+ pool,
+ opts
+ )
+ ],
+ [
+ WorkerChoiceStrategies.FAIR_SHARE,
+ new (FairShareWorkerChoiceStrategy.bind(this))<Worker, Data, Response>(
+ pool,
+ opts
+ )
+ ],
+ [
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN,
+ new (WeightedRoundRobinWorkerChoiceStrategy.bind(this))<
+ Worker,
+ Data,
+ Response
+ >(pool, opts)
+ ],
+ [
+ WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN,
+ new (InterleavedWeightedRoundRobinWorkerChoiceStrategy.bind(this))<
+ Worker,
+ Data,
+ Response
+ >(pool, opts)
+ ]
+ ])
+ }
+
+ /**
+ * Gets the strategy policy in the context.
+ *
+ * @returns The strategy policy.
+ */
+ public getStrategyPolicy (): StrategyPolicy {
+ return (
+ this.workerChoiceStrategies.get(
+ this.workerChoiceStrategy
+ ) as IWorkerChoiceStrategy
+ ).strategyPolicy