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 | 10 | export interface TaskError<Data = unknown> { |
ff128cc9 JB |
11 | /** |
12 | * Task name triggering the error. | |
13 | */ | |
14 | readonly name: string | |
82f36766 JB |
15 | /** |
16 | * Error message. | |
17 | */ | |
eb7bf744 | 18 | readonly message: string |
82f36766 | 19 | /** |
ff128cc9 | 20 | * Data triggering the error. |
82f36766 | 21 | */ |
eb7bf744 | 22 | readonly data?: Data |
82f36766 JB |
23 | } |
24 | ||
d715b7bc JB |
25 | /** |
26 | * Task performance. | |
f03062df JB |
27 | * |
28 | * @internal | |
d715b7bc JB |
29 | */ |
30 | export interface TaskPerformance { | |
197b4aa5 JB |
31 | /** |
32 | * Task name. | |
33 | */ | |
34 | readonly name: string | |
d715b7bc JB |
35 | /** |
36 | * Task performance timestamp. | |
37 | */ | |
eb7bf744 | 38 | readonly timestamp: number |
d715b7bc JB |
39 | /** |
40 | * Task runtime. | |
41 | */ | |
eb7bf744 | 42 | readonly runTime?: number |
d715b7bc JB |
43 | /** |
44 | * Task event loop utilization. | |
45 | */ | |
eb7bf744 | 46 | readonly elu?: EventLoopUtilization |
d715b7bc JB |
47 | } |
48 | ||
b6b32453 JB |
49 | /** |
50 | * Performance statistics computation. | |
f03062df JB |
51 | * |
52 | * @internal | |
b6b32453 JB |
53 | */ |
54 | export interface WorkerStatistics { | |
55 | runTime: boolean | |
b6b32453 JB |
56 | elu: boolean |
57 | } | |
58 | ||
729c563d | 59 | /** |
02706357 | 60 | * Message object that is passed between main worker and worker. |
c319c66b | 61 | * |
e102732c JB |
62 | * @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data. |
63 | * @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data. | |
71ebe93b | 64 | * @internal |
729c563d | 65 | */ |
6677a3d3 JB |
66 | export interface MessageValue<Data = unknown, ErrorData = unknown> |
67 | extends Task<Data> { | |
729c563d S |
68 | /** |
69 | * Kill code. | |
70 | */ | |
48487131 | 71 | readonly kill?: KillBehavior | true |
729c563d | 72 | /** |
91ee39ed | 73 | * Task error. |
729c563d | 74 | */ |
e102732c | 75 | readonly taskError?: TaskError<ErrorData> |
bf9549ae | 76 | /** |
d715b7bc | 77 | * Task performance. |
62c15a68 | 78 | */ |
d715b7bc | 79 | readonly taskPerformance?: TaskPerformance |
b6b32453 | 80 | /** |
f59e1027 | 81 | * Whether the worker computes the given statistics or not. |
b6b32453 JB |
82 | */ |
83 | readonly statistics?: WorkerStatistics | |
f59e1027 | 84 | /** |
7c8381eb | 85 | * Whether the worker is ready or not. |
f59e1027 | 86 | */ |
7c8381eb | 87 | readonly ready?: boolean |
75d3401a | 88 | /** |
48487131 | 89 | * Whether the worker starts or stops its aliveness check. |
75d3401a | 90 | */ |
48487131 | 91 | readonly checkAlive?: boolean |
325f50bc | 92 | } |
be0676b3 APA |
93 | |
94 | /** | |
2740a743 | 95 | * An object holding the execution response promise resolve/reject callbacks. |
be0676b3 | 96 | * |
ae94ec4d | 97 | * @typeParam Worker - Type of worker. |
e102732c | 98 | * @typeParam Response - Type of execution response. This can only be structured-cloneable data. |
c319c66b | 99 | * @internal |
be0676b3 | 100 | */ |
c923ce56 | 101 | export interface PromiseResponseWrapper< |
f06e48d8 | 102 | Worker extends IWorker, |
c923ce56 JB |
103 | Response = unknown |
104 | > { | |
be0676b3 APA |
105 | /** |
106 | * Resolve callback to fulfill the promise. | |
107 | */ | |
108 | readonly resolve: (value: Response) => void | |
109 | /** | |
110 | * Reject callback to reject the promise. | |
111 | */ | |
112 | readonly reject: (reason?: string) => void | |
113 | /** | |
a3445496 | 114 | * The worker handling the execution. |
be0676b3 | 115 | */ |
c923ce56 | 116 | readonly worker: Worker |
be0676b3 | 117 | } |