Add dynamic worker choice strategy change at runtime
[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 */
14 LESS_RECENTLY_USED: 'LESS_RECENTLY_USED'
15} as const)
16
17/**
18 * Worker choice strategy.
19 */
20export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
21
22/**
23 * Worker choice strategy interface.
24 *
25 * @template Worker Type of worker which manages the strategy.
26 */
27export interface IWorkerChoiceStrategy<Worker extends AbstractPoolWorker> {
28 /**
29 * Is the pool attached to the strategy dynamic?.
30 */
31 isDynamicPool: boolean
32 /**
33 * Choose a worker in the pool.
34 */
35 choose(): Worker
36}