Strict boolean check
[poolifier.git] / src / pools / selection-strategies / selection-strategies-types.ts
CommitLineData
bdaf31cd
JB
1import type { AbstractPoolWorker } from '../abstract-pool-worker'
2
3/**
4 * Enumeration of worker choice strategies.
5 */
6export 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 14 LESS_RECENTLY_USED: 'LESS_RECENTLY_USED',
23ff945a
JB
15 /**
16 * Fair share worker selection strategy.
17 */
18 FAIR_SHARE: 'FAIR_SHARE',
b3432a63
JB
19 /**
20 * Weighted round robin worker selection strategy.
21 */
22 WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN'
bdaf31cd
JB
23} as const)
24
25/**
26 * Worker choice strategy.
27 */
28export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
29
10fcfaf4
JB
30/**
31 * Tasks usage statistics requirements.
32 */
33export type RequiredStatistics = {
34 runTime: boolean
35}
36
bdaf31cd
JB
37/**
38 * Worker choice strategy interface.
39 *
40 * @template Worker Type of worker which manages the strategy.
41 */
42export interface IWorkerChoiceStrategy<Worker extends AbstractPoolWorker> {
43 /**
44 * Is the pool attached to the strategy dynamic?.
45 */
46 isDynamicPool: boolean
10fcfaf4
JB
47 /**
48 * Required tasks usage statistics.
49 */
50 requiredStatistics: RequiredStatistics
bdaf31cd 51 /**
bdede008 52 * Chooses a worker in the pool.
bdaf31cd
JB
53 */
54 choose(): Worker
55}