-import type { AbstractPoolWorker } from '../abstract-pool-worker'
import type { IPoolInternal } from '../pool-internal'
+import type { IPoolWorker } from '../pool-worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
import { SelectionStrategiesUtils } from './selection-strategies-utils'
/**
- * Dynamically choose a worker.
+ * Selects the next worker for dynamic pool.
*
* @template Worker Type of worker which manages the strategy.
* @template Data Type of data sent to the worker. This can only be serializable data.
* @template Response Type of response of execution. This can only be serializable data.
*/
export class DynamicPoolWorkerChoiceStrategy<
- Worker extends AbstractPoolWorker,
+ Worker extends IPoolWorker,
Data,
Response
> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> {
private workerChoiceStrategy: IWorkerChoiceStrategy<Worker>
/**
- * Constructs a worker choice strategy for dynamical pool.
+ * Constructs a worker choice strategy for dynamic pool.
*
* @param pool The pool instance.
* @param createDynamicallyWorkerCallback The worker creation callback for dynamic pool.
*/
public constructor (
pool: IPoolInternal<Worker, Data, Response>,
- private createDynamicallyWorkerCallback: () => Worker,
+ private readonly createDynamicallyWorkerCallback: () => Worker,
workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
) {
super(pool)
this.pool,
workerChoiceStrategy
)
+ this.requiredStatistics = this.workerChoiceStrategy.requiredStatistics
}
- /** @inheritdoc */
+ /** @inheritDoc */
+ public reset (): boolean {
+ return this.workerChoiceStrategy.reset()
+ }
+
+ /** @inheritDoc */
public choose (): Worker {
const freeWorker = this.pool.findFreeWorker()
if (freeWorker) {
return freeWorker
}
- if (this.pool.busy) {
+ if (this.pool.busy === true) {
return this.workerChoiceStrategy.choose()
}