X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fpool-internal.ts;h=dd71ae71045b555d99b64a24bba516461c77b561;hb=2ea51d625067ca54eba5b8781ec8070dd28966d2;hp=ddee27eac0ed21bf43ca4f61b8378ee3a3146b6a;hpb=a35560bac09e829e1e19f88f8fd1d71a64c9d50b;p=poolifier.git diff --git a/src/pools/pool-internal.ts b/src/pools/pool-internal.ts index ddee27ea..dd71ae71 100644 --- a/src/pools/pool-internal.ts +++ b/src/pools/pool-internal.ts @@ -1,8 +1,15 @@ import EventEmitter from 'events' -import type { MessageValue } from '../utility-types' import type { IWorker } from './abstract-pool' import type { IPool } from './pool' +/** + * Pool types. + */ +export enum PoolType { + FIXED = 'fixed', + DYNAMIC = 'dynamic' +} + /** * Internal poolifier pool emitter. */ @@ -38,44 +45,42 @@ export interface IPoolInternal< * * Events that can currently be listened to: * - * - `'FullPool'` + * - `'busy'` */ - readonly emitter: PoolEmitter + readonly emitter?: PoolEmitter /** - * Maximum number of workers that can be created by this pool. + * Pool type. + * + * If it is `'dynamic'`, it provides the `max` property. */ - readonly max?: number + readonly type: PoolType /** - * Whether the pool is dynamic or not. - * - * If it is dynamic, it provides the `max` property. + * Maximum number of workers that can be created by this pool. */ - isDynamic(): boolean + readonly max?: number /** - * Creates a new worker for this pool and sets it up completely. + * Whether the pool is busy or not. * - * @returns New, completely set up worker. + * The pool busyness boolean status. */ - createAndSetupWorker(): Worker + readonly busy: boolean /** - * Shut down given worker. - * - * @param worker A worker within `workers`. + * Number of tasks currently concurrently running. */ - destroyWorker(worker: Worker): void | Promise + readonly numberOfRunningTasks: number /** - * Register a listener callback on a given worker. + * 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. * - * @param worker A worker. - * @param listener A message listener callback. + * @returns A tasks map entry with a free worker if there was one, otherwise `false`. */ - registerWorkerMessageListener( - worker: Worker, - listener: (message: MessageValue) => void - ): void + findFreeTasksMapEntry(): [Worker, number] | false }