0443b4ceef2374e28ba8201bf5d1d6a61ebbce93
1 import type { EventLoopUtilization
} from
'node:perf_hooks'
2 import type { KillBehavior
} from
'./worker/worker-options'
3 import type { IWorker
, Task
} from
'./pools/worker'
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
> {
16 * Data passed to the worker triggering the error.
24 export interface TaskPerformance
{
26 * Task performance timestamp.
34 * Task event loop utilization.
36 elu
?: EventLoopUtilization
40 * Performance statistics computation.
42 export interface WorkerStatistics
{
48 * Message object that is passed between main worker and worker.
50 * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
51 * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
54 export interface MessageValue
<Data
= unknown
, ErrorData
= unknown
>
59 readonly workerId
?: number
63 readonly kill
?: KillBehavior
| 1
67 readonly taskError
?: TaskError
<ErrorData
>
71 readonly taskPerformance
?: TaskPerformance
73 * Whether the worker computes the given statistics or not.
75 readonly statistics
?: WorkerStatistics
77 * Whether the worker has started or not.
79 readonly started
?: boolean
83 * An object holding the execution response promise resolve/reject callbacks.
85 * @typeParam Worker - Type of worker.
86 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
89 export interface PromiseResponseWrapper
<
90 Worker
extends IWorker
,
94 * Resolve callback to fulfill the promise.
96 readonly resolve
: (value
: Response
) => void
98 * Reject callback to reject the promise.
100 readonly reject
: (reason
?: string) => void
102 * The worker handling the execution.
104 readonly worker
: Worker