X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fless-busy-worker-choice-strategy.ts;h=87ef804d50881f157e2810a715c2db4627315f33;hb=a22cdf86c993800ec9ea8ae32ef0d8dbda07ec61;hp=61e2d369db8e0b6280d03ca6d5277c5e63bef8c9;hpb=c141008c44abbc291b45355aa5b8fef5d3ba1de7;p=poolifier.git diff --git a/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts index 61e2d369..87ef804d 100644 --- a/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts @@ -1,6 +1,9 @@ import type { IPoolWorker } from '../pool-worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' -import type { RequiredStatistics } from './selection-strategies-types' +import type { + IWorkerChoiceStrategy, + RequiredStatistics +} from './selection-strategies-types' /** * Selects the less busy worker. @@ -10,24 +13,27 @@ import type { RequiredStatistics } from './selection-strategies-types' * @typeParam Response - Type of response of execution. This can only be serializable data. */ export class LessBusyWorkerChoiceStrategy< - Worker extends IPoolWorker, - Data, - Response -> extends AbstractWorkerChoiceStrategy { - /** {@inheritDoc} */ + Worker extends IPoolWorker, + Data = unknown, + Response = unknown + > + extends AbstractWorkerChoiceStrategy + implements IWorkerChoiceStrategy { + /** @inheritDoc */ public readonly requiredStatistics: RequiredStatistics = { - runTime: true + runTime: true, + avgRunTime: false } - /** {@inheritDoc} */ + /** @inheritDoc */ public reset (): boolean { return true } - /** {@inheritDoc} */ + /** @inheritDoc */ public choose (): number { const freeWorkerKey = this.pool.findFreeWorkerKey() - if (!this.isDynamicPool && freeWorkerKey !== false) { + if (freeWorkerKey !== -1) { return freeWorkerKey } let minRunTime = Infinity @@ -44,7 +50,7 @@ export class LessBusyWorkerChoiceStrategy< return lessBusyWorkerKey } - /** {@inheritDoc} */ + /** @inheritDoc */ public remove (workerKey: number): boolean { return true }