1 import type { IPoolInternal
} from
'../pool-internal'
2 import { PoolType
} from
'../pool-internal'
3 import type { IWorker
} from
'../worker'
7 WorkerChoiceStrategyOptions
8 } from
'./selection-strategies-types'
11 * Worker choice strategy abstract base class.
13 * @typeParam Worker - Type of worker which manages the strategy.
14 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
15 * @typeParam Response - Type of response of execution. This can only be serializable data.
17 export abstract class AbstractWorkerChoiceStrategy
<
18 Worker
extends IWorker
,
21 > implements IWorkerChoiceStrategy
{
23 protected readonly isDynamicPool
: boolean
25 public readonly requiredStatistics
: RequiredStatistics
= {
32 * Constructs a worker choice strategy bound to the pool.
34 * @param pool - The pool instance.
35 * @param opts - The worker choice strategy options.
38 protected readonly pool
: IPoolInternal
<Worker
, Data
, Response
>,
39 protected readonly opts
: WorkerChoiceStrategyOptions
= { medRunTime
: false }
42 this.isDynamicPool
= this.pool
.type === PoolType
.DYNAMIC
43 this.choose
.bind(this)
46 private checkOptions (): void {
47 if (this.requiredStatistics
.avgRunTime
&& this.opts
.medRunTime
=== true) {
48 this.requiredStatistics
.medRunTime
= true
53 public abstract reset (): boolean
56 public abstract choose (): number
59 public abstract remove (workerNodeKey
: number): boolean