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