1 import type { IPool
} from
'./pool'
2 import type { IPoolWorker
} from
'./pool-worker'
13 * Internal tasks usage statistics.
15 export interface TasksUsage
{
23 * Internal worker type.
25 * @typeParam Worker - Type of worker which manages this pool.
27 export interface WorkerType
<Worker
extends IPoolWorker
> {
29 tasksUsage
: TasksUsage
33 * Internal contract definition for a poolifier pool.
35 * @typeParam Worker - Type of worker which manages this pool.
36 * @typeParam Data - Type of data sent to the worker.
37 * @typeParam Response - Type of response of execution.
39 export interface IPoolInternal
<
40 Worker
extends IPoolWorker
,
43 > extends IPool
<Data
, Response
> {
47 readonly workers
: Map
<number, WorkerType
<Worker
>>
52 * If it is `'dynamic'`, it provides the `max` property.
54 readonly type: PoolType
57 * Whether the pool is busy or not.
59 * The pool busyness boolean status.
61 readonly busy
: boolean
64 * Number of tasks currently concurrently running.
66 readonly numberOfRunningTasks
: number
69 * Finds a free worker based on the number of tasks the worker has applied.
71 * If a worker is found with `0` running tasks, it is detected as free and returned.
73 * If no free worker is found, `false` is returned.
75 * @returns A free worker if there is one, otherwise `false`.
77 findFreeWorker
: () => Worker
| false
80 * Gets worker running tasks.
82 * @param worker - The worker.
83 * @returns The number of tasks currently running on the worker.
85 getWorkerRunningTasks
: (worker
: Worker
) => number | undefined
88 * Gets worker average tasks runtime.
90 * @param worker - The worker.
91 * @returns The average tasks runtime on the worker.
93 getWorkerAverageTasksRunTime
: (worker
: Worker
) => number | undefined