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 WorkerError
<Data
= unknown
> {
12 * Task function 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 * Worker task performance statistics computation settings.
54 export interface WorkerStatistics
{
56 * Whether the worker computes the task runtime or not.
58 readonly runTime
: boolean
60 * Whether the worker computes the task event loop utilization (ELU) or not.
66 * Message object that is passed as a task between main worker and worker.
68 * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
71 export interface Task
<Data
= unknown
> {
75 readonly workerId
?: number
79 readonly name
?: string
81 * Task input data that will be passed to the worker.
85 * Array of transferable objects.
87 readonly transferList
?: TransferListItem
[]
91 readonly timestamp
?: number
95 readonly taskId
?: string
99 * Message object that is passed between main worker and worker.
101 * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
102 * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
105 export interface MessageValue
<Data
= unknown
, ErrorData
= unknown
>
110 readonly kill
?: KillBehavior
| true | 'success' | 'failure'
114 readonly workerError
?: WorkerError
<ErrorData
>
118 readonly taskPerformance
?: TaskPerformance
120 * Task function operation:
121 * - `'add'` - Add a task function.
122 * - `'delete'` - Delete a task function.
123 * - `'default'` - Set a task function as default.
125 readonly taskFunctionOperation
?: 'add' | 'remove' | 'default'
127 * Whether the task function operation is successful or not.
129 readonly taskFunctionOperationStatus
?: boolean
131 * Task function serialized to string.
133 readonly taskFunction
?: string
135 * Task function name.
137 readonly taskFunctionName
?: string
139 * Task function names.
141 readonly taskFunctionNames
?: string[]
143 * Whether the worker computes the given statistics or not.
145 readonly statistics
?: WorkerStatistics
147 * Whether the worker is ready or not.
149 readonly ready
?: boolean
151 * Whether the worker starts or stops its activity check.
153 readonly checkActive
?: boolean
157 readonly port
?: MessagePort
161 * An object holding the task execution response promise resolve/reject callbacks.
163 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
166 export interface PromiseResponseWrapper
<Response
= unknown
> {
168 * Resolve callback to fulfill the promise.
170 readonly resolve
: (value
: Response
| PromiseLike
<Response
>) => void
172 * Reject callback to reject the promise.
174 readonly reject
: (reason
?: unknown
) => void
176 * The worker node key executing the task.
178 readonly workerNodeKey
: number
181 export type Writable
<T
> = { -readonly [P
in keyof T
]: T
[P
] }