Commit | Line | Data |
---|---|---|
a35560ba | 1 | import type { IPool } from './pool' |
ea7a90d3 | 2 | import type { IPoolWorker } from './pool-worker' |
a35560ba | 3 | |
7c0ba920 | 4 | /** |
b4904890 | 5 | * Internal pool types. |
7c0ba920 JB |
6 | */ |
7 | export enum PoolType { | |
8 | FIXED = 'fixed', | |
9 | DYNAMIC = 'dynamic' | |
10 | } | |
11 | ||
bf9549ae | 12 | /** |
b4904890 | 13 | * Internal tasks usage statistics. |
bf9549ae JB |
14 | */ |
15 | export interface TasksUsage { | |
16 | run: number | |
17 | running: number | |
18 | runTime: number | |
19 | avgRunTime: number | |
2740a743 | 20 | error: number |
bf9549ae JB |
21 | } |
22 | ||
ffcbbad8 JB |
23 | /** |
24 | * Internal worker type. | |
25 | * | |
26 | * @typeParam Worker - Type of worker which manages this pool. | |
27 | */ | |
28 | export interface WorkerType<Worker extends IPoolWorker> { | |
29 | worker: Worker | |
30 | tasksUsage: TasksUsage | |
31 | } | |
32 | ||
a35560ba S |
33 | /** |
34 | * Internal contract definition for a poolifier pool. | |
35 | * | |
38e795c1 JB |
36 | * @typeParam Worker - Type of worker which manages this pool. |
37 | * @typeParam Data - Type of data sent to the worker. | |
38 | * @typeParam Response - Type of response of execution. | |
a35560ba S |
39 | */ |
40 | export interface IPoolInternal< | |
ea7a90d3 | 41 | Worker extends IPoolWorker, |
a35560ba S |
42 | Data = unknown, |
43 | Response = unknown | |
44 | > extends IPool<Data, Response> { | |
45 | /** | |
c2ade475 | 46 | * Pool worker type items array. |
a35560ba | 47 | */ |
e65c6cd9 | 48 | readonly workers: Array<WorkerType<Worker>> |
ea7a90d3 | 49 | |
a35560ba | 50 | /** |
7c0ba920 | 51 | * Pool type. |
a35560ba | 52 | * |
7c0ba920 | 53 | * If it is `'dynamic'`, it provides the `max` property. |
a35560ba | 54 | */ |
7c0ba920 | 55 | readonly type: PoolType |
ff5e76e1 | 56 | |
7c0ba920 | 57 | /** |
c2ade475 | 58 | * Whether the pool is full or not. |
7c0ba920 | 59 | * |
c2ade475 | 60 | * The pool filling boolean status. |
7c0ba920 | 61 | */ |
c2ade475 | 62 | readonly full: boolean |
7c0ba920 JB |
63 | |
64 | /** | |
c2ade475 JB |
65 | * Whether the pool is busy or not. |
66 | * | |
67 | * The pool busyness boolean status. | |
7c0ba920 | 68 | */ |
c2ade475 | 69 | readonly busy: boolean |
7c0ba920 JB |
70 | |
71 | /** | |
c923ce56 | 72 | * Finds a free worker key based on the number of tasks the worker has applied. |
7c0ba920 | 73 | * |
c923ce56 | 74 | * If a worker is found with `0` running tasks, it is detected as free and its key is returned. |
7c0ba920 | 75 | * |
bdaf31cd | 76 | * If no free worker is found, `false` is returned. |
7c0ba920 | 77 | * |
bf90656c | 78 | * @returns A worker key if there is one, `-1` otherwise. |
7c0ba920 | 79 | */ |
bf90656c | 80 | findFreeWorkerKey: () => number |
a35560ba | 81 | } |