X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fpool-internal.ts;h=dd71ae71045b555d99b64a24bba516461c77b561;hb=9b2fdd9fbe65595ae80ff429b633ab2222188946;hp=d641fcf9d9fec246ee26a92a67a78d348b3dacf3;hpb=ff5e76e152be8540cba8118bb4e2b9da314dfff5;p=poolifier.git diff --git a/src/pools/pool-internal.ts b/src/pools/pool-internal.ts index d641fcf9..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,16 +45,16 @@ export interface IPoolInternal< * * Events that can currently be listened to: * - * - `'FullPool'` + * - `'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. @@ -55,27 +62,25 @@ export interface IPoolInternal< 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 }