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.
30 export interface TaskPerformance
{
32 * Task performance timestamp.
34 readonly timestamp
: number
38 readonly runTime
?: number
40 * Task event loop utilization.
42 readonly elu
?: EventLoopUtilization
46 * Performance statistics computation.
50 export interface WorkerStatistics
{
56 * Message object that is passed between main worker and worker.
58 * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
59 * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
62 export interface MessageValue
<Data
= unknown
, ErrorData
= unknown
>
67 readonly workerId
?: number
71 readonly kill
?: KillBehavior
| true
75 readonly taskError
?: TaskError
<ErrorData
>
79 readonly taskPerformance
?: TaskPerformance
81 * Whether the worker computes the given statistics or not.
83 readonly statistics
?: WorkerStatistics
85 * Whether the worker has started or not.
87 readonly started
?: boolean
89 * Whether the worker starts or stops its aliveness check.
91 readonly checkAlive
?: boolean
95 * An object holding the execution response promise resolve/reject callbacks.
97 * @typeParam Worker - Type of worker.
98 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
101 export interface PromiseResponseWrapper
<
102 Worker
extends IWorker
,
106 * Resolve callback to fulfill the promise.
108 readonly resolve
: (value
: Response
) => void
110 * Reject callback to reject the promise.
112 readonly reject
: (reason
?: string) => void
114 * The worker handling the execution.
116 readonly worker
: Worker