X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker.ts;h=d9dd43865bf6d36cb7d4bb6ce808eccf3528a7c8;hb=8cc4ea811611b8ad77c7b0379911afe497f2e7e4;hp=5ac90fbf1783e9e04a7e820e37c961e8527385ff;hpb=b558f6b5a5625753de41024325e40e1cbd03eda1;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 5ac90fbf..d9dd4386 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -2,6 +2,11 @@ import type { MessageChannel } from 'node:worker_threads' import type { CircularArray } from '../circular-array' import type { Task } from '../utility-types' +/** + * Callback invoked when the worker has started successfully. + */ +export type OnlineHandler = (this: Worker) => void + /** * Callback invoked if the worker has received a message. */ @@ -18,11 +23,6 @@ export type ErrorHandler = ( error: Error ) => void -/** - * Callback invoked when the worker has started successfully. - */ -export type OnlineHandler = (this: Worker) => void - /** * Callback invoked when the worker exits successfully. */ @@ -141,10 +141,6 @@ export interface WorkerInfo { * Task function names. */ taskFunctions?: string[] - /** - * Message channel. - */ - messageChannel?: MessageChannel } /** @@ -215,6 +211,10 @@ export interface IWorkerNode { * Worker info. */ readonly info: WorkerInfo + /** + * Message channel. + */ + readonly messageChannel?: MessageChannel /** * Worker usage statistics. */ @@ -243,15 +243,24 @@ export interface IWorkerNode { */ readonly clearTasksQueue: () => void /** - * Resets usage statistics . + * Whether the worker node has back pressure (i.e. its tasks queue is full). + * + * @returns `true` if the worker node has back pressure, `false` otherwise. + */ + readonly hasBackPressure: () => boolean + /** + * Resets usage statistics. */ readonly resetUsage: () => void /** - * Close communication channel. + * Closes communication channel. */ readonly closeChannel: () => void /** - * Gets task worker usage statistics. + * Gets task function worker usage statistics. + * + * @param name - The task function name. + * @returns The task function worker usage statistics if the task function worker usage statistics are initialized, `undefined` otherwise. */ - readonly getTaskWorkerUsage: (name: string) => WorkerUsage | undefined + readonly getTaskFunctionWorkerUsage: (name: string) => WorkerUsage | undefined }