1 import type { Worker
as ClusterWorker
} from
'node:cluster'
2 import type { MessagePort
} from
'node:worker_threads'
3 import type { EventLoopUtilization
} from
'node:perf_hooks'
4 import type { KillBehavior
} from
'./worker/worker-options'
5 import type { IWorker
, Task
} from
'./pools/worker'
8 * Make all properties in T non-readonly.
10 * @typeParam T - Type in which properties will be non-readonly.
12 export type Draft
<T
> = { -readonly [P
in keyof T
]?: T
[P
] }
17 export interface TaskPerformance
{
19 * Task performance timestamp.
31 * Task event loop utilization.
33 elu
?: EventLoopUtilization
37 * Performance statistics computation.
39 export interface WorkerStatistics
{
46 * Message object that is passed between main worker and worker.
48 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
49 * @typeParam MainWorker - Type of main worker.
52 export interface MessageValue
<
54 MainWorker
extends ClusterWorker
| MessagePort
= ClusterWorker
| MessagePort
55 > extends Task
<Data
> {
59 readonly kill
?: KillBehavior
| 1
63 readonly error
?: string
65 * Task data triggering task error.
67 readonly errorData
?: unknown
71 readonly taskPerformance
?: TaskPerformance
73 * Reference to main worker.
75 readonly parent?: MainWorker
77 * Whether to compute the given statistics or not.
79 readonly statistics
?: WorkerStatistics
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 serializable 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