X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fworker-choice-strategy-context.ts;h=9a015347bc2a430172855116224da8cfc89f2800;hb=af7fe15acbe47c6b2236426034dd5cb08c271bbc;hp=cf1b005169d8fbaa04fb074adb4f3f2966cbe335;hpb=449cd15417158c0d1675a8aec8bcc514ff33b5a3;p=poolifier.git diff --git a/src/pools/selection-strategies/worker-choice-strategy-context.ts b/src/pools/selection-strategies/worker-choice-strategy-context.ts index cf1b0051..9a015347 100644 --- a/src/pools/selection-strategies/worker-choice-strategy-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategy-context.ts @@ -1,4 +1,4 @@ -import { getDefaultInternalWorkerChoiceStrategyOptions } from '../../utils' +import { buildInternalWorkerChoiceStrategyOptions } from '../../utils' import type { IPool } from '../pool' import type { IWorker } from '../worker' import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy' @@ -46,14 +46,10 @@ export class WorkerChoiceStrategyContext< private workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN, private opts?: InternalWorkerChoiceStrategyOptions ) { - this.opts = { - ...getDefaultInternalWorkerChoiceStrategyOptions( - pool.info.maxSize + - Object.keys((this.opts?.weights as Record) ?? {}) - .length - ), - ...this.opts - } + this.opts = buildInternalWorkerChoiceStrategyOptions( + pool.info.maxSize, + this.opts + ) this.execute = this.execute.bind(this) this.workerChoiceStrategies = new Map< WorkerChoiceStrategy, @@ -235,13 +231,10 @@ export class WorkerChoiceStrategyContext< pool: IPool, opts?: InternalWorkerChoiceStrategyOptions ): void { - this.opts = { - ...getDefaultInternalWorkerChoiceStrategyOptions( - pool.info.maxSize + - Object.keys((opts?.weights as Record) ?? {}).length - ), - ...opts - } + this.opts = buildInternalWorkerChoiceStrategyOptions( + pool.info.maxSize, + opts + ) for (const workerChoiceStrategy of this.workerChoiceStrategies.values()) { workerChoiceStrategy.setOptions(this.opts) }