Commit | Line | Data |
---|---|---|
bdaf31cd JB |
1 | import type { AbstractPoolWorker } from '../abstract-pool-worker' |
2 | ||
3 | /** | |
4 | * Enumeration of worker choice strategies. | |
5 | */ | |
6 | export const WorkerChoiceStrategies = Object.freeze({ | |
7 | /** | |
8 | * Round robin worker selection strategy. | |
9 | */ | |
10 | ROUND_ROBIN: 'ROUND_ROBIN', | |
11 | /** | |
12 | * Less recently used worker selection strategy. | |
13 | */ | |
b3432a63 JB |
14 | LESS_RECENTLY_USED: 'LESS_RECENTLY_USED', |
15 | /** | |
16 | * Weighted round robin worker selection strategy. | |
17 | */ | |
18 | WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN' | |
bdaf31cd JB |
19 | } as const) |
20 | ||
21 | /** | |
22 | * Worker choice strategy. | |
23 | */ | |
24 | export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies | |
25 | ||
26 | /** | |
27 | * Worker choice strategy interface. | |
28 | * | |
29 | * @template Worker Type of worker which manages the strategy. | |
30 | */ | |
31 | export interface IWorkerChoiceStrategy<Worker extends AbstractPoolWorker> { | |
32 | /** | |
33 | * Is the pool attached to the strategy dynamic?. | |
34 | */ | |
35 | isDynamicPool: boolean | |
36 | /** | |
37 | * Choose a worker in the pool. | |
38 | */ | |
39 | choose(): Worker | |
40 | } |