1 import type { IPoolInternal
} from
'../pool-internal'
2 import type { IPoolWorker
} from
'../pool-worker'
5 * Enumeration of worker choice strategies.
7 export const WorkerChoiceStrategies
= Object.freeze({
9 * Round robin worker selection strategy.
11 ROUND_ROBIN
: 'ROUND_ROBIN',
13 * Less used worker selection strategy.
15 LESS_USED
: 'LESS_USED',
17 * Less busy worker selection strategy.
19 LESS_BUSY
: 'LESS_BUSY',
21 * Fair share worker selection strategy.
23 FAIR_SHARE
: 'FAIR_SHARE',
25 * Weighted round robin worker selection strategy.
27 WEIGHTED_ROUND_ROBIN
: 'WEIGHTED_ROUND_ROBIN'
31 * Worker choice strategy.
33 export type WorkerChoiceStrategy
= keyof
typeof WorkerChoiceStrategies
36 * Pool worker tasks usage statistics requirements.
38 export interface RequiredStatistics
{
44 * Worker choice strategy interface.
46 export interface IWorkerChoiceStrategy
<
47 Worker
extends IPoolWorker
,
54 readonly pool
: IPoolInternal
<Worker
, Data
, Response
>
56 * Is the pool bound to the strategy dynamic?.
58 readonly isDynamicPool
: boolean
60 * Required pool tasks usage statistics.
62 readonly requiredStatistics
: RequiredStatistics
64 * Resets strategy internals (counters, statistics, etc.).
68 * Chooses a worker in the pool and returns its key.
72 * Removes a worker reference from strategy internals.
74 * @param workerKey - The worker key.
76 remove
: (workerKey
: number) => boolean