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
> {
14 readonly workerId
: number
18 readonly message
: string
20 * Data passed to the worker triggering the error.
28 export interface TaskPerformance
{
30 * Task performance timestamp.
32 readonly timestamp
: number
36 readonly runTime
?: number
38 * Task event loop utilization.
40 readonly elu
?: EventLoopUtilization
44 * Performance statistics computation.
46 export interface WorkerStatistics
{
52 * Message object that is passed between main worker and worker.
54 * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
55 * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
58 export interface MessageValue
<Data
= unknown
, ErrorData
= unknown
>
63 readonly workerId
?: number
67 readonly kill
?: KillBehavior
| 1
71 readonly taskError
?: TaskError
<ErrorData
>
75 readonly taskPerformance
?: TaskPerformance
77 * Whether the worker computes the given statistics or not.
79 readonly statistics
?: WorkerStatistics
81 * Whether the worker has started or not.
83 readonly started
?: boolean
87 * An object holding the execution response promise resolve/reject callbacks.
89 * @typeParam Worker - Type of worker.
90 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
93 export interface PromiseResponseWrapper
<
94 Worker
extends IWorker
,
98 * Resolve callback to fulfill the promise.
100 readonly resolve
: (value
: Response
) => void
102 * Reject callback to reject the promise.
104 readonly reject
: (reason
?: string) => void
106 * The worker handling the execution.
108 readonly worker
: Worker