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