Commit | Line | Data |
---|---|---|
fc3e6586 JB |
1 | import type { Worker as ClusterWorker } from 'node:cluster' |
2 | import type { MessagePort } from 'node:worker_threads' | |
1a81f8af | 3 | import type { KillBehavior } from './worker/worker-options' |
f06e48d8 | 4 | import type { IWorker } from './pools/worker' |
838898f1 | 5 | |
729c563d | 6 | /** |
3832ad95 | 7 | * Make all properties in T non-readonly. |
729c563d | 8 | */ |
325f50bc S |
9 | export type Draft<T> = { -readonly [P in keyof T]?: T[P] } |
10 | ||
729c563d S |
11 | /** |
12 | * Message object that is passed between worker and main worker. | |
c319c66b JB |
13 | * |
14 | * @typeParam Data - Type of data sent to the worker. This can only be serializable data. | |
15 | * @typeParam MainWorker - Type of main worker. | |
729c563d | 16 | */ |
838898f1 S |
17 | export interface MessageValue< |
18 | Data = unknown, | |
cc9b8d30 | 19 | MainWorker extends ClusterWorker | MessagePort | unknown = unknown |
838898f1 | 20 | > { |
729c563d S |
21 | /** |
22 | * Input data that will be passed to the worker. | |
23 | */ | |
325f50bc | 24 | readonly data?: Data |
729c563d | 25 | /** |
e088a00c | 26 | * Id of the message. |
729c563d | 27 | */ |
b4e75778 | 28 | readonly id?: string |
729c563d S |
29 | /** |
30 | * Kill code. | |
31 | */ | |
1a81f8af | 32 | readonly kill?: KillBehavior | 1 |
729c563d S |
33 | /** |
34 | * Error. | |
35 | */ | |
325f50bc | 36 | readonly error?: string |
bf9549ae | 37 | /** |
aee46736 | 38 | * Runtime. |
bf9549ae | 39 | */ |
aee46736 | 40 | readonly runTime?: number |
729c563d S |
41 | /** |
42 | * Reference to main worker. | |
43 | * | |
90a9a10f | 44 | * Only for internal use. |
50e66724 | 45 | * @internal |
729c563d | 46 | */ |
838898f1 | 47 | readonly parent?: MainWorker |
325f50bc | 48 | } |
be0676b3 APA |
49 | |
50 | /** | |
2740a743 | 51 | * An object holding the execution response promise resolve/reject callbacks. |
be0676b3 | 52 | * |
ae94ec4d | 53 | * @typeParam Worker - Type of worker. |
2740a743 | 54 | * @typeParam Response - Type of execution response. This can only be serializable data. |
c319c66b | 55 | * @internal |
be0676b3 | 56 | */ |
c923ce56 | 57 | export interface PromiseResponseWrapper< |
f06e48d8 | 58 | Worker extends IWorker, |
c923ce56 JB |
59 | Response = unknown |
60 | > { | |
be0676b3 APA |
61 | /** |
62 | * Resolve callback to fulfill the promise. | |
63 | */ | |
64 | readonly resolve: (value: Response) => void | |
65 | /** | |
66 | * Reject callback to reject the promise. | |
67 | */ | |
68 | readonly reject: (reason?: string) => void | |
69 | /** | |
a3445496 | 70 | * The worker handling the execution. |
be0676b3 | 71 | */ |
c923ce56 | 72 | readonly worker: Worker |
be0676b3 | 73 | } |