-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
utility-types.ts
113 lines (108 loc) · 2.46 KB
/
utility-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import type { EventLoopUtilization } from 'node:perf_hooks'
import type { KillBehavior } from './worker/worker-options'
import type { IWorker, Task } from './pools/worker'
/**
* Task error.
*
* @typeParam Data - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
*/
export interface TaskError<Data = unknown> {
/**
* Worker id.
*/
readonly workerId: number
/**
* Error message.
*/
readonly message: string
/**
* Data passed to the worker triggering the error.
*/
readonly data?: Data
}
/**
* Task performance.
*
* @internal
*/
export interface TaskPerformance {
/**
* Task performance timestamp.
*/
readonly timestamp: number
/**
* Task runtime.
*/
readonly runTime?: number
/**
* Task event loop utilization.
*/
readonly elu?: EventLoopUtilization
}
/**
* Performance statistics computation.
*
* @internal
*/
export interface WorkerStatistics {
runTime: boolean
elu: boolean
}
/**
* Message object that is passed between main worker and worker.
*
* @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
* @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
* @internal
*/
export interface MessageValue<Data = unknown, ErrorData = unknown>
extends Task<Data> {
/**
* Worker id.
*/
readonly workerId?: number
/**
* Kill code.
*/
readonly kill?: KillBehavior | 1
/**
* Task error.
*/
readonly taskError?: TaskError<ErrorData>
/**
* Task performance.
*/
readonly taskPerformance?: TaskPerformance
/**
* Whether the worker computes the given statistics or not.
*/
readonly statistics?: WorkerStatistics
/**
* Whether the worker has started or not.
*/
readonly started?: boolean
}
/**
* An object holding the execution response promise resolve/reject callbacks.
*
* @typeParam Worker - Type of worker.
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
* @internal
*/
export interface PromiseResponseWrapper<
Worker extends IWorker,
Response = unknown
> {
/**
* Resolve callback to fulfill the promise.
*/
readonly resolve: (value: Response) => void
/**
* Reject callback to reject the promise.
*/
readonly reject: (reason?: string) => void
/**
* The worker handling the execution.
*/
readonly worker: Worker
}