Merge branch 'master' of github.com:jerome-benoit/poolifier
[poolifier.git] / src / pools / pool-internal.ts
CommitLineData
a35560ba 1import type { IPool } from './pool'
f06e48d8 2import type { IWorker, WorkerNode } from './worker'
a35560ba 3
7c0ba920 4/**
b4904890 5 * Internal pool types.
d99ba5a8
JB
6 *
7 * @enum
7c0ba920
JB
8 */
9export enum PoolType {
10 FIXED = 'fixed',
11 DYNAMIC = 'dynamic'
12}
13
a35560ba
S
14/**
15 * Internal contract definition for a poolifier pool.
16 *
38e795c1 17 * @typeParam Worker - Type of worker which manages this pool.
9cd39dd4
JB
18 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
19 * @typeParam Response - Type of response of execution. This can only be serializable data.
a35560ba
S
20 */
21export interface IPoolInternal<
f06e48d8 22 Worker extends IWorker,
a35560ba
S
23 Data = unknown,
24 Response = unknown
25> extends IPool<Data, Response> {
26 /**
f06e48d8 27 * Pool worker nodes.
a35560ba 28 */
f06e48d8 29 readonly workerNodes: Array<WorkerNode<Worker, Data>>
ea7a90d3 30
a35560ba 31 /**
7c0ba920 32 * Pool type.
a35560ba 33 *
7c0ba920 34 * If it is `'dynamic'`, it provides the `max` property.
a35560ba 35 */
7c0ba920 36 readonly type: PoolType
ff5e76e1 37
7c0ba920 38 /**
c2ade475 39 * Whether the pool is full or not.
7c0ba920 40 *
c2ade475 41 * The pool filling boolean status.
7c0ba920 42 */
c2ade475 43 readonly full: boolean
7c0ba920
JB
44
45 /**
c2ade475
JB
46 * Whether the pool is busy or not.
47 *
48 * The pool busyness boolean status.
7c0ba920 49 */
c2ade475 50 readonly busy: boolean
7c0ba920
JB
51
52 /**
f06e48d8 53 * Finds a free worker node key based on the number of tasks the worker has applied.
7c0ba920 54 *
f06e48d8 55 * If a worker is found with `0` running tasks, it is detected as free and its worker node key is returned.
7c0ba920 56 *
dba3384e 57 * If no free worker is found, `-1` is returned.
7c0ba920 58 *
f06e48d8 59 * @returns A worker node key if there is one, `-1` otherwise.
7c0ba920 60 */
f06e48d8 61 findFreeWorkerNodeKey: () => number
a35560ba 62}