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 kill
?: KillBehavior
| 1
63 readonly taskError
?: TaskError
<ErrorData
>
67 readonly taskPerformance
?: TaskPerformance
69 * Whether the worker computes the given statistics or not.
71 readonly statistics
?: WorkerStatistics
75 * An object holding the execution response promise resolve/reject callbacks.
77 * @typeParam Worker - Type of worker.
78 * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
81 export interface PromiseResponseWrapper
<
82 Worker
extends IWorker
,
86 * Resolve callback to fulfill the promise.
88 readonly resolve
: (value
: Response
) => void
90 * Reject callback to reject the promise.
92 readonly reject
: (reason
?: string) => void
94 * The worker handling the execution.
96 readonly worker
: Worker