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' |
838898f1 | 4 | |
729c563d | 5 | /** |
3832ad95 | 6 | * Make all properties in T non-readonly. |
729c563d | 7 | */ |
325f50bc S |
8 | export type Draft<T> = { -readonly [P in keyof T]?: T[P] } |
9 | ||
729c563d S |
10 | /** |
11 | * Message object that is passed between worker and main worker. | |
12 | */ | |
838898f1 S |
13 | export interface MessageValue< |
14 | Data = unknown, | |
cc9b8d30 | 15 | MainWorker extends ClusterWorker | MessagePort | unknown = unknown |
838898f1 | 16 | > { |
729c563d S |
17 | /** |
18 | * Input data that will be passed to the worker. | |
19 | */ | |
325f50bc | 20 | readonly data?: Data |
729c563d | 21 | /** |
e088a00c | 22 | * Id of the message. |
729c563d | 23 | */ |
b4e75778 | 24 | readonly id?: string |
729c563d S |
25 | /** |
26 | * Kill code. | |
27 | */ | |
1a81f8af | 28 | readonly kill?: KillBehavior | 1 |
729c563d S |
29 | /** |
30 | * Error. | |
31 | */ | |
325f50bc | 32 | readonly error?: string |
bf9549ae | 33 | /** |
23135a89 | 34 | * Task runtime. |
bf9549ae JB |
35 | */ |
36 | readonly taskRunTime?: number | |
729c563d S |
37 | /** |
38 | * Reference to main worker. | |
39 | * | |
90a9a10f | 40 | * Only for internal use. |
729c563d | 41 | */ |
838898f1 | 42 | readonly parent?: MainWorker |
325f50bc | 43 | } |
be0676b3 APA |
44 | |
45 | /** | |
2740a743 | 46 | * An object holding the execution response promise resolve/reject callbacks. |
be0676b3 | 47 | * |
2740a743 | 48 | * @typeParam Response - Type of execution response. This can only be serializable data. |
be0676b3 | 49 | */ |
2740a743 | 50 | export interface PromiseResponseWrapper<Response = unknown> { |
be0676b3 APA |
51 | /** |
52 | * Resolve callback to fulfill the promise. | |
53 | */ | |
54 | readonly resolve: (value: Response) => void | |
55 | /** | |
56 | * Reject callback to reject the promise. | |
57 | */ | |
58 | readonly reject: (reason?: string) => void | |
59 | /** | |
2740a743 | 60 | * The worker handling the promise key . |
be0676b3 | 61 | */ |
2740a743 | 62 | readonly workerKey: number |
be0676b3 | 63 | } |