X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fless-busy-worker-choice-strategy.ts;h=9952a41df80fc191fcbcc829d5389f7f720ba02c;hb=2285a040e7d48457c735547e296939b0341d29fd;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..9952a41d 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,13 +13,16 @@ 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 { + Worker extends IPoolWorker, + Data = unknown, + Response = unknown + > + extends AbstractWorkerChoiceStrategy + implements IWorkerChoiceStrategy { /** {@inheritDoc} */ public readonly requiredStatistics: RequiredStatistics = { - runTime: true + runTime: true, + avgRunTime: false } /** {@inheritDoc} */ @@ -27,7 +33,7 @@ export class LessBusyWorkerChoiceStrategy< /** {@inheritDoc} */ public choose (): number { const freeWorkerKey = this.pool.findFreeWorkerKey() - if (!this.isDynamicPool && freeWorkerKey !== false) { + if (freeWorkerKey !== -1) { return freeWorkerKey } let minRunTime = Infinity