1 import type { EventLoopUtilization
} from
'node:perf_hooks'
2 import type { MessagePort
} from
'node:worker_threads'
3 import type { KillBehavior
} from
'./worker/worker-options'
4 import type { IWorker
} from
'./pools/worker'
9 * @typeParam Data - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
11 export interface TaskError
<Data
= unknown
> {
13 * Task name triggering the error.
19 readonly message
: string
21 * Data triggering the error.
31 export interface TaskPerformance
{
37 * Task performance timestamp.
39 readonly timestamp
: number
43 readonly runTime
?: number
45 * Task event loop utilization.
47 readonly elu
?: EventLoopUtilization
51 * Performance statistics computation.
55 export interface WorkerStatistics
{
61 * Message object that is passed as a task between main worker and worker.
63 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
66 export interface Task
<Data
= unknown
> {
70 readonly workerId
: number
74 readonly name
?: string
76 * Task input data that will be passed to the worker.
82 readonly timestamp
?: number
90 * Message object that is passed between main worker and worker.
92 * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
93 * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
96 export interface MessageValue
<Data
= unknown
, ErrorData
= unknown
>
101 readonly kill
?: KillBehavior
| true
105 readonly taskError
?: TaskError
<ErrorData
>
109 readonly taskPerformance
?: TaskPerformance
111 * Whether the worker computes the given statistics or not.
113 readonly statistics
?: WorkerStatistics
115 * Whether the worker is ready or not.
117 readonly ready
?: boolean
119 * Whether the worker starts or stops its activity check.
121 readonly checkActive
?: boolean
125 readonly port
?: MessagePort
129 * An object holding the execution response promise resolve/reject callbacks.
131 * @typeParam Worker - Type of worker.
132 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
135 export interface PromiseResponseWrapper
<
136 Worker
extends IWorker
,
140 * Resolve callback to fulfill the promise.
142 readonly resolve
: (value
: Response
| PromiseLike
<Response
>) => void
144 * Reject callback to reject the promise.
146 readonly reject
: (reason
?: unknown
) => void
148 * The worker handling the execution.
150 readonly worker
: Worker