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 * 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 taskError
?: TaskError
<ErrorData
>
118 readonly taskPerformance
?: TaskPerformance
120 * Task function names.
122 readonly taskFunctions
?: string[]
124 * Whether the worker computes the given statistics or not.
126 readonly statistics
?: WorkerStatistics
128 * Whether the worker is ready or not.
130 readonly ready
?: boolean
132 * Whether the worker starts or stops its activity check.
134 readonly checkActive
?: boolean
138 readonly port
?: MessagePort
142 * An object holding the task execution response promise resolve/reject callbacks.
144 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
147 export interface PromiseResponseWrapper
<Response
= unknown
> {
149 * Resolve callback to fulfill the promise.
151 readonly resolve
: (value
: Response
| PromiseLike
<Response
>) => void
153 * Reject callback to reject the promise.
155 readonly reject
: (reason
?: unknown
) => void
157 * The worker node key executing the task.
159 readonly workerNodeKey
: number
162 export type Writable
<T
> = { -readonly [P
in keyof T
]: T
[P
] }