1 import type { Worker
as ClusterWorker
} from
'node:cluster'
2 import type { MessagePort
} from
'node:worker_threads'
3 import type { KillBehavior
} from
'./worker/worker-options'
4 import type { IWorker
, Task
} from
'./pools/worker'
7 * Make all properties in T non-readonly.
9 * @typeParam T - Type in which properties will be non-readonly.
11 export type Draft
<T
> = { -readonly [P
in keyof T
]?: T
[P
] }
14 * Message object that is passed between main worker and worker.
16 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
17 * @typeParam MainWorker - Type of main worker.
20 export interface MessageValue
<
22 MainWorker
extends ClusterWorker
| MessagePort
| unknown
= unknown
23 > extends Task
<Data
> {
27 readonly kill
?: KillBehavior
| 1
31 readonly error
?: string
35 readonly runTime
?: number
37 * Reference to main worker.
39 readonly parent?: MainWorker
43 * An object holding the execution response promise resolve/reject callbacks.
45 * @typeParam Worker - Type of worker.
46 * @typeParam Response - Type of execution response. This can only be serializable data.
49 export interface PromiseResponseWrapper
<
50 Worker
extends IWorker
,
54 * Resolve callback to fulfill the promise.
56 readonly resolve
: (value
: Response
) => void
58 * Reject callback to reject the promise.
60 readonly reject
: (reason
?: string) => void
62 * The worker handling the execution.
64 readonly worker
: Worker