X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker.ts;h=14c8dbe1e1d444f5404e8562c1c59ecf1585d869;hb=e57eb4d0ea721c4dea66047c431d516f74270453;hp=cd395bbdd0301948937bc7c1ba06d3f2f68d540f;hpb=671d515455c745dc74f4c385fe23683975bfc3df;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index cd395bbd..14c8dbe1 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -212,13 +212,30 @@ 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 + /** + * Callback invoked when worker node tasks queue is empty. + * + * @param workerId - The worker id. + */ + onEmptyQueue?: (workerId: number) => void /** * Tasks queue size. * @@ -229,27 +246,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 /** @@ -257,7 +287,10 @@ export interface IWorkerNode { */ 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 }