470ccdd5938e04ac8585ddc1fb6afc906919d02e
1 import type { IPool
} from
'./pool'
2 import type { IPoolWorker
} from
'./pool-worker'
13 * Internal tasks usage statistics.
15 export interface TasksUsage
{
23 * Internal contract definition for a poolifier pool.
25 * @template Worker Type of worker which manages this pool.
26 * @template Data Type of data sent to the worker.
27 * @template Response Type of response of execution.
29 export interface IPoolInternal
<
30 Worker
extends IPoolWorker
,
33 > extends IPool
<Data
, Response
> {
35 * List of currently available workers.
37 readonly workers
: Worker
[]
40 * The workers tasks usage map.
43 * `value`: Worker tasks usage statistics.
45 readonly workersTasksUsage
: Map
<Worker
, TasksUsage
>
50 * If it is `'dynamic'`, it provides the `max` property.
52 readonly type: PoolType
55 * Maximum number of workers that can be created by this pool.
60 * Whether the pool is busy or not.
62 * The pool busyness boolean status.
64 readonly busy
: boolean
67 * Number of tasks currently concurrently running.
69 readonly numberOfRunningTasks
: number
72 * Finds a free worker based on the number of tasks the worker has applied.
74 * If a worker is found with `0` running tasks, it is detected as free and returned.
76 * If no free worker is found, `false` is returned.
78 * @returns A free worker if there is one, otherwise `false`.
80 findFreeWorker(): Worker
| false
85 * @param worker The worker.
86 * @returns The worker index.
88 getWorkerIndex(worker
: Worker
): number
91 * Gets worker running tasks.
93 * @param worker The worker.
94 * @returns The number of tasks currently running on the worker.
96 getWorkerRunningTasks(worker
: Worker
): number | undefined
99 * Gets worker average tasks runtime.
101 * @param worker The worker.
102 * @returns The average tasks runtime on the worker.
104 getWorkerAverageTasksRunTime(worker
: Worker
): number | undefined