Add dynamic worker choice strategy change at runtime
[poolifier.git] / src / pools / selection-strategies / abstract-worker-choice-strategy.ts
1 import type { AbstractPoolWorker } from '../abstract-pool-worker'
2 import type { IPoolInternal } from '../pool-internal'
3 import { PoolType } from '../pool-internal'
4 import type { IWorkerChoiceStrategy } from './selection-strategies-types'
5
6 /**
7 * Abstract worker choice strategy class.
8 *
9 * @template Worker Type of worker which manages the strategy.
10 * @template Data Type of data sent to the worker. This can only be serializable data.
11 * @template Response Type of response of execution. This can only be serializable data.
12 */
13 export abstract class AbstractWorkerChoiceStrategy<
14 Worker extends AbstractPoolWorker,
15 Data,
16 Response
17 > implements IWorkerChoiceStrategy<Worker> {
18 /** @inheritdoc */
19 public isDynamicPool: boolean = this.pool.type === PoolType.DYNAMIC
20
21 /**
22 * Constructs a worker choice strategy attached to the pool.
23 *
24 * @param pool The pool instance.
25 */
26 public constructor (
27 protected readonly pool: IPoolInternal<Worker, Data, Response>
28 ) {}
29
30 /** @inheritdoc */
31 public abstract choose (): Worker
32 }