Commit | Line | Data |
---|---|---|
62c15a68 | 1 | import type { EventLoopUtilization } from 'node:perf_hooks' |
1a81f8af | 2 | import type { KillBehavior } from './worker/worker-options' |
02706357 | 3 | import type { IWorker, Task } from './pools/worker' |
838898f1 | 4 | |
213e817d JB |
5 | /** |
6 | * Task error. | |
7 | * | |
e102732c | 8 | * @typeParam Data - Type of data sent to the worker triggering an error. This can only be structured-cloneable data. |
213e817d | 9 | */ |
82f36766 JB |
10 | export interface TaskError<Data = unknown> { |
11 | /** | |
12 | * Error message. | |
13 | */ | |
14 | message: string | |
15 | /** | |
16 | * Data passed to the worker triggering the error. | |
17 | */ | |
18 | data?: Data | |
19 | } | |
20 | ||
d715b7bc JB |
21 | /** |
22 | * Task performance. | |
23 | */ | |
24 | export interface TaskPerformance { | |
25 | /** | |
26 | * Task performance timestamp. | |
27 | */ | |
28 | timestamp: number | |
29 | /** | |
30 | * Task runtime. | |
31 | */ | |
32 | runTime?: number | |
d715b7bc JB |
33 | /** |
34 | * Task event loop utilization. | |
35 | */ | |
36 | elu?: EventLoopUtilization | |
37 | } | |
38 | ||
b6b32453 JB |
39 | /** |
40 | * Performance statistics computation. | |
41 | */ | |
42 | export interface WorkerStatistics { | |
43 | runTime: boolean | |
b6b32453 JB |
44 | elu: boolean |
45 | } | |
46 | ||
729c563d | 47 | /** |
02706357 | 48 | * Message object that is passed between main worker and worker. |
c319c66b | 49 | * |
e102732c JB |
50 | * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data. |
51 | * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data. | |
c319c66b | 52 | * @typeParam MainWorker - Type of main worker. |
71ebe93b | 53 | * @internal |
729c563d | 54 | */ |
838898f1 S |
55 | export interface MessageValue< |
56 | Data = unknown, | |
e102732c JB |
57 | ErrorData = unknown, |
58 | MainWorker = NodeJS.Process | MessagePort | |
59 | > extends Task<Data> { | |
729c563d S |
60 | /** |
61 | * Kill code. | |
62 | */ | |
1a81f8af | 63 | readonly kill?: KillBehavior | 1 |
729c563d | 64 | /** |
91ee39ed | 65 | * Task error. |
729c563d | 66 | */ |
e102732c | 67 | readonly taskError?: TaskError<ErrorData> |
bf9549ae | 68 | /** |
d715b7bc | 69 | * Task performance. |
62c15a68 | 70 | */ |
d715b7bc | 71 | readonly taskPerformance?: TaskPerformance |
729c563d S |
72 | /** |
73 | * Reference to main worker. | |
729c563d | 74 | */ |
838898f1 | 75 | readonly parent?: MainWorker |
b6b32453 JB |
76 | /** |
77 | * Whether to compute the given statistics or not. | |
78 | */ | |
79 | readonly statistics?: WorkerStatistics | |
325f50bc | 80 | } |
be0676b3 APA |
81 | |
82 | /** | |
2740a743 | 83 | * An object holding the execution response promise resolve/reject callbacks. |
be0676b3 | 84 | * |
ae94ec4d | 85 | * @typeParam Worker - Type of worker. |
e102732c | 86 | * @typeParam Response - Type of execution response. This can only be structured-cloneable data. |
c319c66b | 87 | * @internal |
be0676b3 | 88 | */ |
c923ce56 | 89 | export interface PromiseResponseWrapper< |
f06e48d8 | 90 | Worker extends IWorker, |
c923ce56 JB |
91 | Response = unknown |
92 | > { | |
be0676b3 APA |
93 | /** |
94 | * Resolve callback to fulfill the promise. | |
95 | */ | |
96 | readonly resolve: (value: Response) => void | |
97 | /** | |
98 | * Reject callback to reject the promise. | |
99 | */ | |
100 | readonly reject: (reason?: string) => void | |
101 | /** | |
a3445496 | 102 | * The worker handling the execution. |
be0676b3 | 103 | */ |
c923ce56 | 104 | readonly worker: Worker |
be0676b3 | 105 | } |