Commit | Line | Data |
---|---|---|
a35560ba | 1 | import EventEmitter from 'events' |
a35560ba S |
2 | import type { IWorker } from './abstract-pool' |
3 | import type { IPool } from './pool' | |
4 | ||
5 | /** | |
6 | * Internal poolifier pool emitter. | |
7 | */ | |
8 | export class PoolEmitter extends EventEmitter {} | |
9 | ||
10 | /** | |
11 | * Internal contract definition for a poolifier pool. | |
12 | * | |
13 | * @template Worker Type of worker which manages this pool. | |
14 | * @template Data Type of data sent to the worker. | |
15 | * @template Response Type of response of execution. | |
16 | */ | |
17 | export interface IPoolInternal< | |
18 | Worker extends IWorker, | |
19 | Data = unknown, | |
20 | Response = unknown | |
21 | > extends IPool<Data, Response> { | |
22 | /** | |
23 | * List of currently available workers. | |
24 | */ | |
25 | readonly workers: Worker[] | |
26 | ||
27 | /** | |
28 | * The tasks map. | |
29 | * | |
30 | * - `key`: The `Worker` | |
31 | * - `value`: Number of tasks currently in progress on the worker. | |
32 | */ | |
33 | readonly tasks: Map<Worker, number> | |
34 | ||
35 | /** | |
36 | * Emitter on which events can be listened to. | |
37 | * | |
38 | * Events that can currently be listened to: | |
39 | * | |
330c983e | 40 | * - `'busy'` |
a35560ba S |
41 | */ |
42 | readonly emitter: PoolEmitter | |
43 | ||
a35560ba S |
44 | /** |
45 | * Whether the pool is dynamic or not. | |
46 | * | |
47 | * If it is dynamic, it provides the `max` property. | |
48 | */ | |
ff5e76e1 JB |
49 | readonly dynamic: boolean |
50 | ||
51 | /** | |
52 | * Maximum number of workers that can be created by this pool. | |
53 | */ | |
54 | readonly max?: number | |
a35560ba | 55 | } |