X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fdynamic-pool-worker-choice-strategy.ts;h=81f3df519fecffcd7fa5aaec04a7e3e4cdc14689;hb=a6f7f1b40b3591b19a58f69b22e751c4c4311522;hp=c2053af44f6c72f57768aee83c6ef5f8a47f8b9b;hpb=a76fac14098cf2138cf8d6997ac7c89d8c3ae508;p=poolifier.git diff --git a/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts b/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts index c2053af4..81f3df51 100644 --- a/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts @@ -1,5 +1,5 @@ -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, @@ -9,21 +9,21 @@ import { WorkerChoiceStrategies } from './selection-strategies-types' 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 { private workerChoiceStrategy: IWorkerChoiceStrategy /** - * 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. @@ -39,6 +39,12 @@ export class DynamicPoolWorkerChoiceStrategy< this.pool, workerChoiceStrategy ) + this.requiredStatistics = this.workerChoiceStrategy.requiredStatistics + } + + /** @inheritDoc */ + public reset (): boolean { + return this.workerChoiceStrategy.reset() } /** @inheritDoc */ @@ -48,7 +54,7 @@ export class DynamicPoolWorkerChoiceStrategy< return freeWorker } - if (this.pool.busy) { + if (this.pool.busy === true) { return this.workerChoiceStrategy.choose() }