docs: sync worker choice context constructor comment
[poolifier.git] / src / pools / selection-strategies / selection-strategies-types.ts
CommitLineData
bdaf31cd
JB
1/**
2 * Enumeration of worker choice strategies.
3 */
4export const WorkerChoiceStrategies = Object.freeze({
5 /**
6 * Round robin worker selection strategy.
7 */
8 ROUND_ROBIN: 'ROUND_ROBIN',
9 /**
737c6d97 10 * Less used worker selection strategy.
bdaf31cd 11 */
737c6d97 12 LESS_USED: 'LESS_USED',
168c526f
JB
13 /**
14 * Less busy worker selection strategy.
15 */
16 LESS_BUSY: 'LESS_BUSY',
23ff945a
JB
17 /**
18 * Fair share worker selection strategy.
19 */
20 FAIR_SHARE: 'FAIR_SHARE',
b3432a63
JB
21 /**
22 * Weighted round robin worker selection strategy.
23 */
24 WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN'
bdaf31cd
JB
25} as const)
26
27/**
28 * Worker choice strategy.
29 */
30export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
31
10fcfaf4 32/**
9cd39dd4 33 * Pool worker tasks usage statistics requirements.
10fcfaf4 34 */
78cea37e 35export interface RequiredStatistics {
10fcfaf4 36 runTime: boolean
c6bd2650 37 avgRunTime: boolean
10fcfaf4
JB
38}
39
bdaf31cd
JB
40/**
41 * Worker choice strategy interface.
bdaf31cd 42 */
17393ac8 43export interface IWorkerChoiceStrategy {
10fcfaf4 44 /**
ea7a90d3 45 * Required pool tasks usage statistics.
10fcfaf4 46 */
ea7a90d3
JB
47 readonly requiredStatistics: RequiredStatistics
48 /**
a6f7f1b4 49 * Resets strategy internals (counters, statistics, etc.).
ea7a90d3 50 */
78cea37e 51 reset: () => boolean
bdaf31cd 52 /**
c923ce56 53 * Chooses a worker in the pool and returns its key.
bdaf31cd 54 */
c923ce56 55 choose: () => number
97a2abc3
JB
56 /**
57 * Removes a worker reference from strategy internals.
58 *
59 * @param workerKey - The worker key.
60 */
61 remove: (workerKey: number) => boolean
bdaf31cd 62}