X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fpool.ts;h=e65cc115d2d77c0a0590fa5f936043b16dcb38d2;hb=a6d60641bc8ca8e6c6e6ce15bdf3035cf2a5d192;hp=24b506ca8f3f1f5a7fef66aeb0440af624cc64dd;hpb=ef3891a3674f862e07006d0e1961feb12c41d1d8;p=poolifier.git diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 24b506ca..e65cc115 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -47,7 +47,8 @@ export const PoolEvents = Object.freeze({ full: 'full', destroy: 'destroy', error: 'error', - taskError: 'taskError' + taskError: 'taskError', + backPressure: 'backPressure' } as const) /** @@ -111,6 +112,10 @@ export interface TasksQueueOptions { * @typeParam Worker - Type of worker. */ export interface PoolOptions { + /** + * A function that will listen for online event on each worker. + */ + onlineHandler?: OnlineHandler /** * A function that will listen for message event on each worker. */ @@ -119,10 +124,6 @@ export interface PoolOptions { * A function that will listen for error event on each worker. */ errorHandler?: ErrorHandler - /** - * A function that will listen for online event on each worker. - */ - onlineHandler?: OnlineHandler /** * A function that will listen for exit event on each worker. */ @@ -177,8 +178,18 @@ export interface IPool< readonly info: PoolInfo /** * Pool worker nodes. + * + * @internal */ readonly workerNodes: Array> + /** + * Whether the worker node has back pressure (i.e. its tasks queue is full). + * + * @param workerNodeKey - The worker node key. + * @returns `true` if the worker node has back pressure, `false` otherwise. + * @internal + */ + readonly hasWorkerNodeBackPressure: (workerNodeKey: number) => boolean /** * Emitter on which events can be listened to. * @@ -190,6 +201,7 @@ export interface IPool< * - '`destroy`': Emitted when the pool is destroyed. * - `'error'`: Emitted when an uncaught error occurs. * - `'taskError'`: Emitted when an error occurs while executing a task. + * - `'backPressure'`: Emitted when all worker nodes have back pressure (i.e. their tasks queue is full: queue size \>= pool maximum size^2). */ readonly emitter?: PoolEmitter /**