1 import EventEmitter from
'events'
2 import type { IWorker
} from
'./abstract-pool'
3 import type { IPool
} from
'./pool'
14 * Internal poolifier pool emitter.
16 export class PoolEmitter
extends EventEmitter
{}
19 * Internal contract definition for a poolifier pool.
21 * @template Worker Type of worker which manages this pool.
22 * @template Data Type of data sent to the worker.
23 * @template Response Type of response of execution.
25 export interface IPoolInternal
<
26 Worker
extends IWorker
,
29 > extends IPool
<Data
, Response
> {
31 * List of currently available workers.
33 readonly workers
: Worker
[]
38 * - `key`: The `Worker`
39 * - `value`: Number of tasks currently in progress on the worker.
41 readonly tasks
: Map
<Worker
, number>
44 * Emitter on which events can be listened to.
46 * Events that can currently be listened to:
50 readonly emitter
?: PoolEmitter
55 * If it is `'dynamic'`, it provides the `max` property.
57 readonly type: PoolType
60 * Maximum number of workers that can be created by this pool.
65 * Whether the pool is busy or not.
67 * The pool busyness boolean status.
69 readonly busy
: boolean
72 * Number of tasks currently concurrently running.
74 readonly numberOfRunningTasks
: number
77 * Find a tasks map entry with a free worker based on the number of tasks the worker has applied.
79 * If an entry is found with a worker that has `0` tasks, it is detected as free.
81 * If no tasks map entry with a free worker was found, `false` will be returned.
83 * @returns A tasks map entry with a free worker if there was one, otherwise `false`.
85 findFreeTasksMapEntry(): [Worker
, number] | false