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