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