1 import type { EventLoopUtilization
} from
'node:perf_hooks'
2 import type { MessagePort
} from
'node:worker_threads'
3 import type { KillBehavior
} from
'./worker/worker-options'
8 * @typeParam Data - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
10 export interface TaskError
<Data
= unknown
> {
12 * Task name triggering the error.
18 readonly message
: string
20 * Data triggering the error.
30 export interface TaskPerformance
{
36 * Task performance timestamp.
38 readonly timestamp
: number
42 readonly runTime
?: number
44 * Task event loop utilization.
46 readonly elu
?: EventLoopUtilization
50 * Performance statistics computation.
54 export interface WorkerStatistics
{
60 * Message object that is passed as a task between main worker and worker.
62 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
65 export interface Task
<Data
= unknown
> {
69 readonly workerId
: number
73 readonly name
?: string
75 * Task input data that will be passed to the worker.
81 readonly timestamp
?: number
85 readonly taskId
?: string
89 * Message object that is passed between main worker and worker.
91 * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
92 * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
95 export interface MessageValue
<Data
= unknown
, ErrorData
= unknown
>
100 readonly kill
?: KillBehavior
| true
104 readonly taskError
?: TaskError
<ErrorData
>
108 readonly taskPerformance
?: TaskPerformance
110 * Whether the worker computes the given statistics or not.
112 readonly statistics
?: WorkerStatistics
114 * Whether the worker is ready or not.
116 readonly ready
?: boolean
118 * Whether the worker starts or stops its activity check.
120 readonly checkActive
?: boolean
124 readonly port
?: MessagePort
128 * An object holding the task execution response promise resolve/reject callbacks.
130 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
133 export interface PromiseResponseWrapper
<Response
= unknown
> {
135 * Resolve callback to fulfill the promise.
137 readonly resolve
: (value
: Response
| PromiseLike
<Response
>) => void
139 * Reject callback to reject the promise.
141 readonly reject
: (reason
?: unknown
) => void
143 * The worker node key executing the task.
145 readonly workerNodeKey
: number