import type { IWorker } from '../worker'
import type {
IWorkerChoiceStrategy,
- RequiredStatistics
+ RequiredStatistics,
+ WorkerChoiceStrategyOptions
} from './selection-strategies-types'
/**
/** @inheritDoc */
protected readonly isDynamicPool: boolean
/** @inheritDoc */
- public requiredStatistics: RequiredStatistics = {
+ public readonly requiredStatistics: RequiredStatistics = {
runTime: false,
avgRunTime: false,
medRunTime: false
* Constructs a worker choice strategy bound to the pool.
*
* @param pool - The pool instance.
+ * @param opts - The worker choice strategy options.
*/
public constructor (
- protected readonly pool: IPoolInternal<Worker, Data, Response>
+ protected readonly pool: IPoolInternal<Worker, Data, Response>,
+ protected readonly opts: WorkerChoiceStrategyOptions = { medRunTime: false }
) {
+ this.checkOptions()
this.isDynamicPool = this.pool.type === PoolType.DYNAMIC
this.choose.bind(this)
}
+ private checkOptions (): void {
+ if (this.requiredStatistics.avgRunTime && this.opts.medRunTime === true) {
+ this.requiredStatistics.medRunTime = true
+ }
+ }
+
/** @inheritDoc */
public abstract reset (): boolean