1 import type { CircularArray
} from
'../circular-array'
2 import type { IPool
} from
'./pool'
3 import type { IPoolWorker
} from
'./pool-worker'
10 export enum PoolType
{
16 * Internal tasks usage statistics.
18 export interface TasksUsage
{
22 runTimeHistory
: CircularArray
<number>
29 * Internal worker type.
31 * @typeParam Worker - Type of worker type items which manages this pool.
33 export interface WorkerType
<Worker
extends IPoolWorker
> {
35 tasksUsage
: TasksUsage
39 * Internal contract definition for a poolifier pool.
41 * @typeParam Worker - Type of worker which manages this pool.
42 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
43 * @typeParam Response - Type of response of execution. This can only be serializable data.
45 export interface IPoolInternal
<
46 Worker
extends IPoolWorker
,
49 > extends IPool
<Data
, Response
> {
51 * Pool worker type items array.
53 readonly workers
: Array<WorkerType
<Worker
>>
58 * If it is `'dynamic'`, it provides the `max` property.
60 readonly type: PoolType
63 * Whether the pool is full or not.
65 * The pool filling boolean status.
67 readonly full
: boolean
70 * Whether the pool is busy or not.
72 * The pool busyness boolean status.
74 readonly busy
: boolean
77 * Finds a free worker key based on the number of tasks the worker has applied.
79 * If a worker is found with `0` running tasks, it is detected as free and its key is returned.
81 * If no free worker is found, `-1` is returned.
83 * @returns A worker key if there is one, `-1` otherwise.
85 findFreeWorkerKey
: () => number