X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fpool-internal.ts;h=dd71ae71045b555d99b64a24bba516461c77b561;hb=767e23e80a540dcedab8a2aa5203b8526e3df7b1;hp=911e761df157a07f54ac1300328c82548cc6d9d6;hpb=330c983e06cc9711c66fcd0f1bb419e80453c77f;p=poolifier.git diff --git a/src/pools/pool-internal.ts b/src/pools/pool-internal.ts index 911e761d..dd71ae71 100644 --- a/src/pools/pool-internal.ts +++ b/src/pools/pool-internal.ts @@ -2,6 +2,14 @@ import EventEmitter from 'events' import type { IWorker } from './abstract-pool' import type { IPool } from './pool' +/** + * Pool types. + */ +export enum PoolType { + FIXED = 'fixed', + DYNAMIC = 'dynamic' +} + /** * Internal poolifier pool emitter. */ @@ -39,17 +47,40 @@ export interface IPoolInternal< * * - `'busy'` */ - readonly emitter: PoolEmitter + readonly emitter?: PoolEmitter /** - * Whether the pool is dynamic or not. + * Pool type. * - * If it is dynamic, it provides the `max` property. + * If it is `'dynamic'`, it provides the `max` property. */ - readonly dynamic: boolean + readonly type: PoolType /** * Maximum number of workers that can be created by this pool. */ readonly max?: number + + /** + * Whether the pool is busy or not. + * + * The pool busyness boolean status. + */ + readonly busy: boolean + + /** + * Number of tasks currently concurrently running. + */ + readonly numberOfRunningTasks: number + + /** + * Find a tasks map entry with a free worker based on the number of tasks the worker has applied. + * + * If an entry is found with a worker that has `0` tasks, it is detected as free. + * + * If no tasks map entry with a free worker was found, `false` will be returned. + * + * @returns A tasks map entry with a free worker if there was one, otherwise `false`. + */ + findFreeTasksMapEntry(): [Worker, number] | false }