X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futility-types.ts;h=a418ee885f903d3bb9838c0c34be0e6bbce43524;hb=refs%2Ftags%2Fv2.6.29;hp=f1b773eb31196c5ca827759bbbf3f70a37fc1ae9;hpb=7c8381eb33aaff689afe1944d8643508003cf0b1;p=poolifier.git diff --git a/src/utility-types.ts b/src/utility-types.ts index f1b773eb..a418ee88 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -1,6 +1,6 @@ import type { EventLoopUtilization } from 'node:perf_hooks' +import type { MessagePort, TransferListItem } from 'node:worker_threads' import type { KillBehavior } from './worker/worker-options' -import type { IWorker, Task } from './pools/worker' /** * Task error. @@ -9,15 +9,15 @@ import type { IWorker, Task } from './pools/worker' */ export interface TaskError { /** - * Worker id. + * Task name triggering the error. */ - readonly workerId: number + readonly name: string /** * Error message. */ readonly message: string /** - * Data passed to the worker triggering the error. + * Data triggering the error. */ readonly data?: Data } @@ -28,6 +28,10 @@ export interface TaskError { * @internal */ export interface TaskPerformance { + /** + * Task name. + */ + readonly name: string /** * Task performance timestamp. */ @@ -52,6 +56,39 @@ export interface WorkerStatistics { elu: boolean } +/** + * Message object that is passed as a task between main worker and worker. + * + * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. + * @internal + */ +export interface Task { + /** + * Worker id. + */ + readonly workerId: number + /** + * Task name. + */ + readonly name?: string + /** + * Task input data that will be passed to the worker. + */ + readonly data?: Data + /** + * Array of transferable objects. + */ + readonly transferList?: TransferListItem[] + /** + * Timestamp. + */ + readonly timestamp?: number + /** + * Task UUID. + */ + readonly taskId?: string +} + /** * Message object that is passed between main worker and worker. * @@ -61,14 +98,10 @@ export interface WorkerStatistics { */ export interface MessageValue extends Task { - /** - * Worker id. - */ - readonly workerId?: number /** * Kill code. */ - readonly kill?: KillBehavior | true + readonly kill?: KillBehavior | true | 'success' | 'failure' /** * Task error. */ @@ -77,6 +110,10 @@ export interface MessageValue * Task performance. */ readonly taskPerformance?: TaskPerformance + /** + * Task function names. + */ + readonly taskFunctions?: string[] /** * Whether the worker computes the given statistics or not. */ @@ -86,32 +123,32 @@ export interface MessageValue */ readonly ready?: boolean /** - * Whether the worker starts or stops its aliveness check. + * Whether the worker starts or stops its activity check. + */ + readonly checkActive?: boolean + /** + * Message port. */ - readonly checkAlive?: boolean + readonly port?: MessagePort } /** - * An object holding the execution response promise resolve/reject callbacks. + * An object holding the task execution response promise resolve/reject callbacks. * - * @typeParam Worker - Type of worker. * @typeParam Response - Type of execution response. This can only be structured-cloneable data. * @internal */ -export interface PromiseResponseWrapper< - Worker extends IWorker, - Response = unknown -> { +export interface PromiseResponseWrapper { /** * Resolve callback to fulfill the promise. */ - readonly resolve: (value: Response) => void + readonly resolve: (value: Response | PromiseLike) => void /** * Reject callback to reject the promise. */ - readonly reject: (reason?: string) => void + readonly reject: (reason?: unknown) => void /** - * The worker handling the execution. + * The worker node key executing the task. */ - readonly worker: Worker + readonly workerNodeKey: number }