Commit | Line | Data |
---|---|---|
bdaf31cd JB |
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> { | |
a76fac14 | 18 | /** @inheritDoc */ |
bdaf31cd JB |
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 | ||
a76fac14 | 30 | /** @inheritDoc */ |
bdaf31cd JB |
31 | public abstract choose (): Worker |
32 | } |