import type { IPoolInternal } from '../pool-internal'
-import { PoolType } from '../pool-internal'
import type { IPoolWorker } from '../pool-worker'
import type {
IWorkerChoiceStrategy,
Data,
Response
> {
- private workerChoiceStrategy!: IWorkerChoiceStrategy
+ private workerChoiceStrategy: IWorkerChoiceStrategy<Worker, Data, Response>
/**
* Worker choice strategy context constructor.
* @param workerChoiceStrategy - The worker choice strategy.
*/
public constructor (
- private readonly pool: IPoolInternal<Worker, Data, Response>,
+ pool: IPoolInternal<Worker, Data, Response>,
private readonly createWorkerCallback: () => number,
workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
) {
this.execute.bind(this)
- this.setWorkerChoiceStrategy(workerChoiceStrategy)
+ this.workerChoiceStrategy = getWorkerChoiceStrategy<Worker, Data, Response>(
+ pool,
+ workerChoiceStrategy
+ )
}
/**
* @param workerChoiceStrategy - The worker choice strategy to set.
*/
public setWorkerChoiceStrategy (
+ pool: IPoolInternal<Worker, Data, Response>,
workerChoiceStrategy: WorkerChoiceStrategy
): void {
this.workerChoiceStrategy?.reset()
- this.workerChoiceStrategy = getWorkerChoiceStrategy(
- this.pool,
+ this.workerChoiceStrategy = getWorkerChoiceStrategy<Worker, Data, Response>(
+ pool,
workerChoiceStrategy
)
}
*/
public execute (): number {
if (
- this.pool.type === PoolType.DYNAMIC &&
- !this.pool.full &&
- this.pool.findFreeWorkerKey() === -1
+ this.workerChoiceStrategy.isDynamicPool &&
+ !this.workerChoiceStrategy.pool.full &&
+ this.workerChoiceStrategy.pool.findFreeWorkerKey() === -1
) {
return this.createWorkerCallback()
}