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
] }
15 * Performance statistics computation.
17 export interface WorkerStatistics
{
24 * Message object that is passed between main worker and worker.
26 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
27 * @typeParam MainWorker - Type of main worker.
30 export interface MessageValue
<
32 MainWorker
extends ClusterWorker
| MessagePort
= ClusterWorker
| MessagePort
33 > extends Task
<Data
> {
37 readonly kill
?: KillBehavior
| 1
41 readonly error
?: string
43 * Task data triggering task error.
45 readonly errorData
?: unknown
49 readonly runTime
?: number
53 readonly waitTime
?: number
55 * Event loop utilization.
57 readonly elu
?: EventLoopUtilization
59 * Reference to main worker.
61 readonly parent?: MainWorker
63 * Whether to compute the given statistics or not.
65 readonly statistics
?: WorkerStatistics
69 * An object holding the execution response promise resolve/reject callbacks.
71 * @typeParam Worker - Type of worker.
72 * @typeParam Response - Type of execution response. This can only be serializable data.
75 export interface PromiseResponseWrapper
<
76 Worker
extends IWorker
,
80 * Resolve callback to fulfill the promise.
82 readonly resolve
: (value
: Response
) => void
84 * Reject callback to reject the promise.
86 readonly reject
: (reason
?: string) => void
88 * The worker handling the execution.
90 readonly worker
: Worker