X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker.ts;h=6b387a96088d430d455ed0a4dbb3759c1cbbe86e;hb=251d6ac2d29d7361d671a8df17af51b414ea3b83;hp=3c44f05eae148883c5c83f91304f894d2297e5fc;hpb=2809112e53951451aeb76e86a2dcc263ba80e43c;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 3c44f05e..6b387a96 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -212,13 +212,24 @@ export interface IWorkerNode { */ readonly info: WorkerInfo /** - * Message channel. + * Message channel (worker_threads only). */ readonly messageChannel?: MessageChannel /** * Worker usage statistics. */ usage: WorkerUsage + /** + * Tasks queue back pressure size. + * This is the number of tasks that can be enqueued before the worker node has back pressure. + */ + tasksQueueBackPressureSize: number + /** + * Callback invoked when worker node tasks queue is back pressured. + * + * @param workerId - The worker id. + */ + onBackPressure?: (workerId: number) => void /** * Tasks queue size. * @@ -229,27 +240,40 @@ export interface IWorkerNode { * Enqueue task. * * @param task - The task to queue. - * @returns The task queue size. + * @returns The tasks queue size. */ readonly enqueueTask: (task: Task) => number + /** + * Prepends a task to the tasks queue. + * + * @param task - The task to prepend. + * @returns The tasks queue size. + */ + readonly unshiftTask: (task: Task) => number /** * Dequeue task. * * @returns The dequeued task. */ readonly dequeueTask: () => Task | undefined + /** + * Pops a task from the tasks queue. + * + * @returns The popped task. + */ + readonly popTask: () => Task | undefined /** * Clears tasks queue. */ readonly clearTasksQueue: () => void /** - * Whether the worker node has back pressure. + * 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 . + * Resets usage statistics. */ readonly resetUsage: () => void /** @@ -262,5 +286,5 @@ export interface IWorkerNode { * @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 }