Commit | Line | Data |
---|---|---|
fc3e6586 JB |
1 | import type { Worker as ClusterWorker } from 'node:cluster' |
2 | import type { MessagePort } from 'node:worker_threads' | |
62c15a68 | 3 | import type { EventLoopUtilization } from 'node:perf_hooks' |
1a81f8af | 4 | import type { KillBehavior } from './worker/worker-options' |
02706357 | 5 | import type { IWorker, Task } from './pools/worker' |
838898f1 | 6 | |
729c563d | 7 | /** |
3832ad95 | 8 | * Make all properties in T non-readonly. |
b40ed511 JB |
9 | * |
10 | * @typeParam T - Type in which properties will be non-readonly. | |
729c563d | 11 | */ |
325f50bc S |
12 | export type Draft<T> = { -readonly [P in keyof T]?: T[P] } |
13 | ||
b6b32453 JB |
14 | /** |
15 | * Performance statistics computation. | |
16 | */ | |
17 | export interface WorkerStatistics { | |
18 | runTime: boolean | |
19 | waitTime: boolean | |
20 | elu: boolean | |
21 | } | |
22 | ||
729c563d | 23 | /** |
02706357 | 24 | * Message object that is passed between main worker and worker. |
c319c66b JB |
25 | * |
26 | * @typeParam Data - Type of data sent to the worker. This can only be serializable data. | |
27 | * @typeParam MainWorker - Type of main worker. | |
71ebe93b | 28 | * @internal |
729c563d | 29 | */ |
838898f1 S |
30 | export interface MessageValue< |
31 | Data = unknown, | |
4c0ada52 | 32 | MainWorker extends ClusterWorker | MessagePort = ClusterWorker | MessagePort |
02706357 | 33 | > extends Task<Data> { |
729c563d S |
34 | /** |
35 | * Kill code. | |
36 | */ | |
1a81f8af | 37 | readonly kill?: KillBehavior | 1 |
729c563d | 38 | /** |
91ee39ed | 39 | * Task error. |
729c563d | 40 | */ |
325f50bc | 41 | readonly error?: string |
91ee39ed JB |
42 | /** |
43 | * Task data triggering task error. | |
44 | */ | |
45 | readonly errorData?: unknown | |
bf9549ae | 46 | /** |
aee46736 | 47 | * Runtime. |
bf9549ae | 48 | */ |
aee46736 | 49 | readonly runTime?: number |
09a6305f JB |
50 | /** |
51 | * Wait time. | |
52 | */ | |
53 | readonly waitTime?: number | |
62c15a68 JB |
54 | /** |
55 | * Event loop utilization. | |
56 | */ | |
57 | readonly elu?: EventLoopUtilization | |
729c563d S |
58 | /** |
59 | * Reference to main worker. | |
729c563d | 60 | */ |
838898f1 | 61 | readonly parent?: MainWorker |
b6b32453 JB |
62 | /** |
63 | * Whether to compute the given statistics or not. | |
64 | */ | |
65 | readonly statistics?: WorkerStatistics | |
325f50bc | 66 | } |
be0676b3 APA |
67 | |
68 | /** | |
2740a743 | 69 | * An object holding the execution response promise resolve/reject callbacks. |
be0676b3 | 70 | * |
ae94ec4d | 71 | * @typeParam Worker - Type of worker. |
2740a743 | 72 | * @typeParam Response - Type of execution response. This can only be serializable data. |
c319c66b | 73 | * @internal |
be0676b3 | 74 | */ |
c923ce56 | 75 | export interface PromiseResponseWrapper< |
f06e48d8 | 76 | Worker extends IWorker, |
c923ce56 JB |
77 | Response = unknown |
78 | > { | |
be0676b3 APA |
79 | /** |
80 | * Resolve callback to fulfill the promise. | |
81 | */ | |
82 | readonly resolve: (value: Response) => void | |
83 | /** | |
84 | * Reject callback to reject the promise. | |
85 | */ | |
86 | readonly reject: (reason?: string) => void | |
87 | /** | |
a3445496 | 88 | * The worker handling the execution. |
be0676b3 | 89 | */ |
c923ce56 | 90 | readonly worker: Worker |
be0676b3 | 91 | } |