X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker.ts;h=14c8dbe1e1d444f5404e8562c1c59ecf1585d869;hb=4644f40d90be3919683c0e668bc42e65cfbc9d7d;hp=d6c236591341c2fb73086d62cdb111cecd2a012e;hpb=e2b31e32498626103ef3c737bdffb285087b13e6;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index d6c23659..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,15 +246,28 @@ 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. */ @@ -249,7 +279,7 @@ export interface IWorkerNode { */ readonly hasBackPressure: () => boolean /** - * Resets usage statistics . + * Resets usage statistics. */ readonly resetUsage: () => void /** @@ -262,5 +292,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 }