1 import type { EventLoopUtilization
} from
'node:perf_hooks'
2 import type { MessagePort
, TransferListItem
} 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.
79 * Array of transferable objects.
81 readonly transferList
?: TransferListItem
[]
85 readonly timestamp
?: number
89 readonly taskId
?: string
93 * Message object that is passed between main worker and worker.
95 * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
96 * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
99 export interface MessageValue
<Data
= unknown
, ErrorData
= unknown
>
104 readonly kill
?: KillBehavior
| true | 'success' | 'failure'
108 readonly taskError
?: TaskError
<ErrorData
>
112 readonly taskPerformance
?: TaskPerformance
114 * Task function names.
116 readonly taskFunctions
?: string[]
118 * Whether the worker computes the given statistics or not.
120 readonly statistics
?: WorkerStatistics
122 * Whether the worker is ready or not.
124 readonly ready
?: boolean
126 * Whether the worker starts or stops its activity check.
128 readonly checkActive
?: boolean
132 readonly port
?: MessagePort
136 * An object holding the task execution response promise resolve/reject callbacks.
138 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
141 export interface PromiseResponseWrapper
<Response
= unknown
> {
143 * Resolve callback to fulfill the promise.
145 readonly resolve
: (value
: Response
| PromiseLike
<Response
>) => void
147 * Reject callback to reject the promise.
149 readonly reject
: (reason
?: unknown
) => void
151 * The worker node key executing the task.
153 readonly workerNodeKey
: number
156 export type Writable
<T
> = { -readonly [P
in keyof T
]: T
[P
] }