Commit | Line | Data |
---|---|---|
bdaf31cd JB |
1 | import type { IPoolInternal } from '../pool-internal' |
2 | import { PoolType } from '../pool-internal' | |
ea7a90d3 | 3 | import type { IPoolWorker } from '../pool-worker' |
10fcfaf4 JB |
4 | import type { |
5 | IWorkerChoiceStrategy, | |
6 | RequiredStatistics | |
7 | } from './selection-strategies-types' | |
bdaf31cd JB |
8 | |
9 | /** | |
10 | * Abstract worker choice strategy class. | |
11 | * | |
38e795c1 JB |
12 | * @typeParam Worker - Type of worker which manages the strategy. |
13 | * @typeParam Data - Type of data sent to the worker. This can only be serializable data. | |
14 | * @typeParam Response - Type of response of execution. This can only be serializable data. | |
bdaf31cd JB |
15 | */ |
16 | export abstract class AbstractWorkerChoiceStrategy< | |
ea7a90d3 | 17 | Worker extends IPoolWorker, |
bdaf31cd JB |
18 | Data, |
19 | Response | |
20 | > implements IWorkerChoiceStrategy<Worker> { | |
38e795c1 | 21 | /** {@inheritDoc} */ |
ea7a90d3 | 22 | public readonly isDynamicPool: boolean = this.pool.type === PoolType.DYNAMIC |
38e795c1 | 23 | /** {@inheritDoc} */ |
10fcfaf4 JB |
24 | public requiredStatistics: RequiredStatistics = { |
25 | runTime: false | |
26 | } | |
bdaf31cd JB |
27 | |
28 | /** | |
29 | * Constructs a worker choice strategy attached to the pool. | |
30 | * | |
38e795c1 | 31 | * @param pool - The pool instance. |
bdaf31cd JB |
32 | */ |
33 | public constructor ( | |
34 | protected readonly pool: IPoolInternal<Worker, Data, Response> | |
35 | ) {} | |
36 | ||
38e795c1 | 37 | /** {@inheritDoc} */ |
a6f7f1b4 | 38 | public abstract reset (): boolean |
ea7a90d3 | 39 | |
38e795c1 | 40 | /** {@inheritDoc} */ |
bdaf31cd JB |
41 | public abstract choose (): Worker |
42 | } |