1 import type { IPoolInternal
} from
'../pool-internal'
2 import type { IPoolWorker
} from
'../pool-worker'
3 import { FairShareWorkerChoiceStrategy
} from
'./fair-share-worker-choice-strategy'
4 import { LessRecentlyUsedWorkerChoiceStrategy
} from
'./less-recently-used-worker-choice-strategy'
5 import { RoundRobinWorkerChoiceStrategy
} from
'./round-robin-worker-choice-strategy'
9 } from
'./selection-strategies-types'
10 import { WorkerChoiceStrategies
} from
'./selection-strategies-types'
11 import { WeightedRoundRobinWorkerChoiceStrategy
} from
'./weighted-round-robin-worker-choice-strategy'
14 * Gets the worker choice strategy instance.
16 * @param pool - The pool instance.
17 * @param workerChoiceStrategy - The worker choice strategy.
18 * @returns The worker choice strategy instance.
20 export function getWorkerChoiceStrategy
<
21 Worker
extends IPoolWorker
,
25 pool
: IPoolInternal
<Worker
, Data
, Response
>,
26 workerChoiceStrategy
: WorkerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
27 ): IWorkerChoiceStrategy
<Worker
> {
28 switch (workerChoiceStrategy
) {
29 case WorkerChoiceStrategies
.ROUND_ROBIN
:
30 return new RoundRobinWorkerChoiceStrategy(pool
)
31 case WorkerChoiceStrategies
.LESS_RECENTLY_USED
:
32 return new LessRecentlyUsedWorkerChoiceStrategy(pool
)
33 case WorkerChoiceStrategies
.FAIR_SHARE
:
34 return new FairShareWorkerChoiceStrategy(pool
)
35 case WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
:
36 return new WeightedRoundRobinWorkerChoiceStrategy(pool
)
39 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
40 `Worker choice strategy '${workerChoiceStrategy}' not found`