X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker.ts;h=99c0d9a6feeea35815a520ff95a160d927bcc4fc;hb=97c12ef2b424d9d67bbc0e0d5d9f0c30953c6bf6;hp=ee54c6acc3f17216361f3c20b55b61f74376f260;hpb=ea4b5fd037c5fe09eb6a2810332ad6bed1b5bc7f;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index ee54c6ac..99c0d9a6 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -2,7 +2,7 @@ import type { EventEmitter } from 'node:events' import type { MessageChannel, WorkerOptions } from 'node:worker_threads' import type { CircularArray } from '../circular-array.js' -import type { Task } from '../utility-types.js' +import type { Task, TaskFunctionProperties } from '../utility-types.js' /** * Callback invoked when the worker has started successfully. @@ -134,10 +134,11 @@ export interface TaskStatistics { /** * Enumeration of worker types. */ -export const WorkerTypes = Object.freeze({ - thread: 'thread', - cluster: 'cluster' -} as const) +export const WorkerTypes: Readonly<{ thread: 'thread', cluster: 'cluster' }> = + Object.freeze({ + thread: 'thread', + cluster: 'cluster' + } as const) /** * Worker type. @@ -172,9 +173,14 @@ export interface WorkerInfo { */ stealing: boolean /** - * Task function names. + * Back pressure flag. + * This flag is set to `true` when worker node tasks queue has back pressure. */ - taskFunctionNames?: string[] + backPressure: boolean + /** + * Task functions properties. + */ + taskFunctionsProperties?: TaskFunctionProperties[] } /** @@ -266,6 +272,7 @@ export interface WorkerNodeOptions { workerOptions?: WorkerOptions env?: Record tasksQueueBackPressureSize: number | undefined + tasksQueueBucketSize: number | undefined } /** @@ -316,25 +323,19 @@ export interface IWorkerNode * @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. * + * @param bucket - The prioritized bucket to dequeue from. @defaultValue 0 * @returns The dequeued task. */ - readonly dequeueTask: () => Task | undefined + readonly dequeueTask: (bucket?: number) => Task | undefined /** - * Pops a task from the tasks queue. + * Dequeue last prioritized task. * - * @returns The popped task. + * @returns The dequeued task. */ - readonly popTask: () => Task | undefined + readonly dequeueLastPrioritizedTask: () => Task | undefined /** * Clears tasks queue. */ @@ -345,10 +346,6 @@ export interface IWorkerNode * @returns `true` if the worker node has back pressure, `false` otherwise. */ readonly hasBackPressure: () => boolean - /** - * Resets usage statistics. - */ - readonly resetUsage: () => void /** * Terminates the worker node. */