X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fless-used-worker-choice-strategy.ts;h=e3c395f477e4adb1d8a042ca71317c84111aae60;hb=c5bdad1403f9ff0bf1e69a702cdec8918a6be25b;hp=166de7069f60f32d1f396576fd8416e9ba87907d;hpb=027063571693f211b35c8851566a063201adb9af;p=poolifier.git diff --git a/src/pools/selection-strategies/less-used-worker-choice-strategy.ts b/src/pools/selection-strategies/less-used-worker-choice-strategy.ts index 166de706..e3c395f4 100644 --- a/src/pools/selection-strategies/less-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-used-worker-choice-strategy.ts @@ -1,6 +1,11 @@ +import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils' +import type { IPool } from '../pool' import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' -import type { IWorkerChoiceStrategy } from './selection-strategies-types' +import type { + IWorkerChoiceStrategy, + WorkerChoiceStrategyOptions +} from './selection-strategies-types' /** * Selects the less used worker. @@ -16,6 +21,15 @@ export class LessUsedWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public constructor ( + pool: IPool, + opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS + ) { + super(pool, opts) + this.checkOptions(this.opts) + } + /** @inheritDoc */ public reset (): boolean { return true @@ -23,7 +37,7 @@ export class LessUsedWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { - const freeWorkerNodeKey = this.pool.findFreeWorkerNodeKey() + const freeWorkerNodeKey = this.findFreeWorkerNodeKey() if (freeWorkerNodeKey !== -1) { return freeWorkerNodeKey }