docs: enhance error message
[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 /**
11 * Fixed pool type.
12 */
13 FIXED = 'fixed',
14 /**
15 * Dynamic pool type.
16 */
17 DYNAMIC = 'dynamic'
18 }
19
20 /**
21 * Internal contract definition for a poolifier pool.
22 *
23 * @typeParam Worker - Type of worker which manages this pool.
24 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
25 * @typeParam Response - Type of response of execution. This can only be serializable data.
26 */
27 export interface IPoolInternal<
28 Worker extends IWorker,
29 Data = unknown,
30 Response = unknown
31 > extends IPool<Data, Response> {
32 /**
33 * Pool worker nodes.
34 */
35 readonly workerNodes: Array<WorkerNode<Worker, Data>>
36
37 /**
38 * Pool type.
39 *
40 * If it is `'dynamic'`, it provides the `max` property.
41 */
42 readonly type: PoolType
43
44 /**
45 * Whether the pool is full or not.
46 *
47 * The pool filling boolean status.
48 */
49 readonly full: boolean
50
51 /**
52 * Whether the pool is busy or not.
53 *
54 * The pool busyness boolean status.
55 */
56 readonly busy: boolean
57
58 /**
59 * Finds a free worker node key based on the number of tasks the worker has applied.
60 *
61 * If a worker is found with `0` running tasks, it is detected as free and its worker node key is returned.
62 *
63 * If no free worker is found, `-1` is returned.
64 *
65 * @returns A worker node key if there is one, `-1` otherwise.
66 */
67 findFreeWorkerNodeKey: () => number
68 }