poolifier 2.6.37 → 2.6.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/lib/index.d.ts +1881 -22
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/package.json +4 -3
- package/lib/circular-array.d.ts +0 -22
- package/lib/deque.d.ts +0 -83
- package/lib/pools/abstract-pool.d.ts +0 -316
- package/lib/pools/cluster/dynamic.d.ts +0 -29
- package/lib/pools/cluster/fixed.d.ts +0 -62
- package/lib/pools/pool.d.ts +0 -243
- package/lib/pools/selection-strategies/abstract-worker-choice-strategy.d.ts +0 -104
- package/lib/pools/selection-strategies/fair-share-worker-choice-strategy.d.ts +0 -39
- package/lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.d.ts +0 -39
- package/lib/pools/selection-strategies/least-busy-worker-choice-strategy.d.ts +0 -26
- package/lib/pools/selection-strategies/least-elu-worker-choice-strategy.d.ts +0 -26
- package/lib/pools/selection-strategies/least-used-worker-choice-strategy.d.ts +0 -24
- package/lib/pools/selection-strategies/round-robin-worker-choice-strategy.d.ts +0 -24
- package/lib/pools/selection-strategies/selection-strategies-types.d.ts +0 -200
- package/lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.d.ts +0 -35
- package/lib/pools/selection-strategies/worker-choice-strategy-context.d.ts +0 -71
- package/lib/pools/thread/dynamic.d.ts +0 -29
- package/lib/pools/thread/fixed.d.ts +0 -54
- package/lib/pools/version.d.ts +0 -1
- package/lib/pools/worker-node.d.ts +0 -60
- package/lib/pools/worker.d.ts +0 -277
- package/lib/utility-types.d.ts +0 -152
- package/lib/utils.d.ts +0 -123
- package/lib/worker/abstract-worker.d.ts +0 -192
- package/lib/worker/cluster-worker.d.ts +0 -35
- package/lib/worker/task-functions.d.ts +0 -33
- package/lib/worker/thread-worker.d.ts +0 -43
- package/lib/worker/worker-options.d.ts +0 -61
package/lib/pools/version.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const version = "2.6.37";
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { MessageChannel } from 'node:worker_threads';
|
|
3
|
-
import type { Task } from '../utility-types';
|
|
4
|
-
import { type IWorker, type IWorkerNode, type WorkerInfo, type WorkerNodeEventCallback, type WorkerUsage } from './worker';
|
|
5
|
-
/**
|
|
6
|
-
* Worker node.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam Worker - Type of worker.
|
|
9
|
-
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
10
|
-
*/
|
|
11
|
-
export declare class WorkerNode<Worker extends IWorker, Data = unknown> implements IWorkerNode<Worker, Data> {
|
|
12
|
-
/** @inheritdoc */
|
|
13
|
-
readonly worker: Worker;
|
|
14
|
-
/** @inheritdoc */
|
|
15
|
-
readonly info: WorkerInfo;
|
|
16
|
-
/** @inheritdoc */
|
|
17
|
-
usage: WorkerUsage;
|
|
18
|
-
/** @inheritdoc */
|
|
19
|
-
messageChannel?: MessageChannel;
|
|
20
|
-
/** @inheritdoc */
|
|
21
|
-
tasksQueueBackPressureSize: number;
|
|
22
|
-
/** @inheritdoc */
|
|
23
|
-
onBackPressure?: WorkerNodeEventCallback;
|
|
24
|
-
/** @inheritdoc */
|
|
25
|
-
onEmptyQueue?: WorkerNodeEventCallback;
|
|
26
|
-
private readonly tasksQueue;
|
|
27
|
-
private onEmptyQueueCount;
|
|
28
|
-
private readonly taskFunctionsUsage;
|
|
29
|
-
/**
|
|
30
|
-
* Constructs a new worker node.
|
|
31
|
-
*
|
|
32
|
-
* @param worker - The worker.
|
|
33
|
-
* @param tasksQueueBackPressureSize - The tasks queue back pressure size.
|
|
34
|
-
*/
|
|
35
|
-
constructor(worker: Worker, tasksQueueBackPressureSize: number);
|
|
36
|
-
/** @inheritdoc */
|
|
37
|
-
tasksQueueSize(): number;
|
|
38
|
-
/** @inheritdoc */
|
|
39
|
-
enqueueTask(task: Task<Data>): number;
|
|
40
|
-
/** @inheritdoc */
|
|
41
|
-
unshiftTask(task: Task<Data>): number;
|
|
42
|
-
/** @inheritdoc */
|
|
43
|
-
dequeueTask(): Task<Data> | undefined;
|
|
44
|
-
/** @inheritdoc */
|
|
45
|
-
popTask(): Task<Data> | undefined;
|
|
46
|
-
/** @inheritdoc */
|
|
47
|
-
clearTasksQueue(): void;
|
|
48
|
-
/** @inheritdoc */
|
|
49
|
-
hasBackPressure(): boolean;
|
|
50
|
-
/** @inheritdoc */
|
|
51
|
-
resetUsage(): void;
|
|
52
|
-
/** @inheritdoc */
|
|
53
|
-
closeChannel(): void;
|
|
54
|
-
/** @inheritdoc */
|
|
55
|
-
getTaskFunctionWorkerUsage(name: string): WorkerUsage | undefined;
|
|
56
|
-
private startOnEmptyQueue;
|
|
57
|
-
private initWorkerInfo;
|
|
58
|
-
private initWorkerUsage;
|
|
59
|
-
private initTaskFunctionWorkerUsage;
|
|
60
|
-
}
|
package/lib/pools/worker.d.ts
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { MessageChannel } from 'node:worker_threads';
|
|
3
|
-
import type { CircularArray } from '../circular-array';
|
|
4
|
-
import type { Task } from '../utility-types';
|
|
5
|
-
/**
|
|
6
|
-
* Callback invoked when the worker has started successfully.
|
|
7
|
-
*/
|
|
8
|
-
export type OnlineHandler<Worker extends IWorker> = (this: Worker) => void;
|
|
9
|
-
/**
|
|
10
|
-
* Callback invoked if the worker has received a message.
|
|
11
|
-
*/
|
|
12
|
-
export type MessageHandler<Worker extends IWorker> = (this: Worker, message: unknown) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Callback invoked if the worker raised an error.
|
|
15
|
-
*/
|
|
16
|
-
export type ErrorHandler<Worker extends IWorker> = (this: Worker, error: Error) => void;
|
|
17
|
-
/**
|
|
18
|
-
* Callback invoked when the worker exits successfully.
|
|
19
|
-
*/
|
|
20
|
-
export type ExitHandler<Worker extends IWorker> = (this: Worker, exitCode: number) => void;
|
|
21
|
-
/**
|
|
22
|
-
* Measurement statistics.
|
|
23
|
-
*
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export interface MeasurementStatistics {
|
|
27
|
-
/**
|
|
28
|
-
* Measurement aggregate.
|
|
29
|
-
*/
|
|
30
|
-
aggregate?: number;
|
|
31
|
-
/**
|
|
32
|
-
* Measurement minimum.
|
|
33
|
-
*/
|
|
34
|
-
minimum?: number;
|
|
35
|
-
/**
|
|
36
|
-
* Measurement maximum.
|
|
37
|
-
*/
|
|
38
|
-
maximum?: number;
|
|
39
|
-
/**
|
|
40
|
-
* Measurement average.
|
|
41
|
-
*/
|
|
42
|
-
average?: number;
|
|
43
|
-
/**
|
|
44
|
-
* Measurement median.
|
|
45
|
-
*/
|
|
46
|
-
median?: number;
|
|
47
|
-
/**
|
|
48
|
-
* Measurement history.
|
|
49
|
-
*/
|
|
50
|
-
readonly history: CircularArray<number>;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Event loop utilization measurement statistics.
|
|
54
|
-
*
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
export interface EventLoopUtilizationMeasurementStatistics {
|
|
58
|
-
readonly idle: MeasurementStatistics;
|
|
59
|
-
readonly active: MeasurementStatistics;
|
|
60
|
-
utilization?: number;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Task statistics.
|
|
64
|
-
*
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
export interface TaskStatistics {
|
|
68
|
-
/**
|
|
69
|
-
* Number of executed tasks.
|
|
70
|
-
*/
|
|
71
|
-
executed: number;
|
|
72
|
-
/**
|
|
73
|
-
* Number of executing tasks.
|
|
74
|
-
*/
|
|
75
|
-
executing: number;
|
|
76
|
-
/**
|
|
77
|
-
* Number of queued tasks.
|
|
78
|
-
*/
|
|
79
|
-
readonly queued: number;
|
|
80
|
-
/**
|
|
81
|
-
* Maximum number of queued tasks.
|
|
82
|
-
*/
|
|
83
|
-
readonly maxQueued?: number;
|
|
84
|
-
/**
|
|
85
|
-
* Number of stolen tasks.
|
|
86
|
-
*/
|
|
87
|
-
stolen: number;
|
|
88
|
-
/**
|
|
89
|
-
* Number of failed tasks.
|
|
90
|
-
*/
|
|
91
|
-
failed: number;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Enumeration of worker types.
|
|
95
|
-
*/
|
|
96
|
-
export declare const WorkerTypes: Readonly<{
|
|
97
|
-
readonly thread: "thread";
|
|
98
|
-
readonly cluster: "cluster";
|
|
99
|
-
}>;
|
|
100
|
-
/**
|
|
101
|
-
* Worker type.
|
|
102
|
-
*/
|
|
103
|
-
export type WorkerType = keyof typeof WorkerTypes;
|
|
104
|
-
/**
|
|
105
|
-
* Worker information.
|
|
106
|
-
*
|
|
107
|
-
* @internal
|
|
108
|
-
*/
|
|
109
|
-
export interface WorkerInfo {
|
|
110
|
-
/**
|
|
111
|
-
* Worker id.
|
|
112
|
-
*/
|
|
113
|
-
readonly id: number | undefined;
|
|
114
|
-
/**
|
|
115
|
-
* Worker type.
|
|
116
|
-
*/
|
|
117
|
-
type: WorkerType;
|
|
118
|
-
/**
|
|
119
|
-
* Dynamic flag.
|
|
120
|
-
*/
|
|
121
|
-
dynamic: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* Ready flag.
|
|
124
|
-
*/
|
|
125
|
-
ready: boolean;
|
|
126
|
-
/**
|
|
127
|
-
* Task function names.
|
|
128
|
-
*/
|
|
129
|
-
taskFunctions?: string[];
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Worker usage statistics.
|
|
133
|
-
*
|
|
134
|
-
* @internal
|
|
135
|
-
*/
|
|
136
|
-
export interface WorkerUsage {
|
|
137
|
-
/**
|
|
138
|
-
* Tasks statistics.
|
|
139
|
-
*/
|
|
140
|
-
readonly tasks: TaskStatistics;
|
|
141
|
-
/**
|
|
142
|
-
* Tasks runtime statistics.
|
|
143
|
-
*/
|
|
144
|
-
readonly runTime: MeasurementStatistics;
|
|
145
|
-
/**
|
|
146
|
-
* Tasks wait time statistics.
|
|
147
|
-
*/
|
|
148
|
-
readonly waitTime: MeasurementStatistics;
|
|
149
|
-
/**
|
|
150
|
-
* Tasks event loop utilization statistics.
|
|
151
|
-
*/
|
|
152
|
-
readonly elu: EventLoopUtilizationMeasurementStatistics;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Worker interface.
|
|
156
|
-
*/
|
|
157
|
-
export interface IWorker {
|
|
158
|
-
/**
|
|
159
|
-
* Worker id.
|
|
160
|
-
*/
|
|
161
|
-
readonly id?: number;
|
|
162
|
-
readonly threadId?: number;
|
|
163
|
-
/**
|
|
164
|
-
* Registers an event listener.
|
|
165
|
-
*
|
|
166
|
-
* @param event - The event.
|
|
167
|
-
* @param handler - The event handler.
|
|
168
|
-
*/
|
|
169
|
-
readonly on: ((event: 'online', handler: OnlineHandler<this>) => void) & ((event: 'message', handler: MessageHandler<this>) => void) & ((event: 'error', handler: ErrorHandler<this>) => void) & ((event: 'exit', handler: ExitHandler<this>) => void);
|
|
170
|
-
/**
|
|
171
|
-
* Registers a listener to the exit event that will only be performed once.
|
|
172
|
-
*
|
|
173
|
-
* @param event - The `'exit'` event.
|
|
174
|
-
* @param handler - The exit handler.
|
|
175
|
-
*/
|
|
176
|
-
readonly once: (event: 'exit', handler: ExitHandler<this>) => void;
|
|
177
|
-
}
|
|
178
|
-
export type WorkerNodeEventCallback = (workerId: number) => void;
|
|
179
|
-
/**
|
|
180
|
-
* Worker node interface.
|
|
181
|
-
*
|
|
182
|
-
* @typeParam Worker - Type of worker.
|
|
183
|
-
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
184
|
-
* @internal
|
|
185
|
-
*/
|
|
186
|
-
export interface IWorkerNode<Worker extends IWorker, Data = unknown> {
|
|
187
|
-
/**
|
|
188
|
-
* Worker.
|
|
189
|
-
*/
|
|
190
|
-
readonly worker: Worker;
|
|
191
|
-
/**
|
|
192
|
-
* Worker info.
|
|
193
|
-
*/
|
|
194
|
-
readonly info: WorkerInfo;
|
|
195
|
-
/**
|
|
196
|
-
* Worker usage statistics.
|
|
197
|
-
*/
|
|
198
|
-
usage: WorkerUsage;
|
|
199
|
-
/**
|
|
200
|
-
* Message channel (worker_threads only).
|
|
201
|
-
*/
|
|
202
|
-
readonly messageChannel?: MessageChannel;
|
|
203
|
-
/**
|
|
204
|
-
* Tasks queue back pressure size.
|
|
205
|
-
* This is the number of tasks that can be enqueued before the worker node has back pressure.
|
|
206
|
-
*/
|
|
207
|
-
tasksQueueBackPressureSize: number;
|
|
208
|
-
/**
|
|
209
|
-
* Callback invoked when worker node tasks queue is back pressured.
|
|
210
|
-
*
|
|
211
|
-
* @param workerId - The worker id.
|
|
212
|
-
*/
|
|
213
|
-
onBackPressure?: WorkerNodeEventCallback;
|
|
214
|
-
/**
|
|
215
|
-
* Callback invoked when worker node tasks queue is empty.
|
|
216
|
-
*
|
|
217
|
-
* @param workerId - The worker id.
|
|
218
|
-
*/
|
|
219
|
-
onEmptyQueue?: WorkerNodeEventCallback;
|
|
220
|
-
/**
|
|
221
|
-
* Tasks queue size.
|
|
222
|
-
*
|
|
223
|
-
* @returns The tasks queue size.
|
|
224
|
-
*/
|
|
225
|
-
readonly tasksQueueSize: () => number;
|
|
226
|
-
/**
|
|
227
|
-
* Enqueue task.
|
|
228
|
-
*
|
|
229
|
-
* @param task - The task to queue.
|
|
230
|
-
* @returns The tasks queue size.
|
|
231
|
-
*/
|
|
232
|
-
readonly enqueueTask: (task: Task<Data>) => number;
|
|
233
|
-
/**
|
|
234
|
-
* Prepends a task to the tasks queue.
|
|
235
|
-
*
|
|
236
|
-
* @param task - The task to prepend.
|
|
237
|
-
* @returns The tasks queue size.
|
|
238
|
-
*/
|
|
239
|
-
readonly unshiftTask: (task: Task<Data>) => number;
|
|
240
|
-
/**
|
|
241
|
-
* Dequeue task.
|
|
242
|
-
*
|
|
243
|
-
* @returns The dequeued task.
|
|
244
|
-
*/
|
|
245
|
-
readonly dequeueTask: () => Task<Data> | undefined;
|
|
246
|
-
/**
|
|
247
|
-
* Pops a task from the tasks queue.
|
|
248
|
-
*
|
|
249
|
-
* @returns The popped task.
|
|
250
|
-
*/
|
|
251
|
-
readonly popTask: () => Task<Data> | undefined;
|
|
252
|
-
/**
|
|
253
|
-
* Clears tasks queue.
|
|
254
|
-
*/
|
|
255
|
-
readonly clearTasksQueue: () => void;
|
|
256
|
-
/**
|
|
257
|
-
* Whether the worker node has back pressure (i.e. its tasks queue is full).
|
|
258
|
-
*
|
|
259
|
-
* @returns `true` if the worker node has back pressure, `false` otherwise.
|
|
260
|
-
*/
|
|
261
|
-
readonly hasBackPressure: () => boolean;
|
|
262
|
-
/**
|
|
263
|
-
* Resets usage statistics.
|
|
264
|
-
*/
|
|
265
|
-
readonly resetUsage: () => void;
|
|
266
|
-
/**
|
|
267
|
-
* Closes communication channel.
|
|
268
|
-
*/
|
|
269
|
-
readonly closeChannel: () => void;
|
|
270
|
-
/**
|
|
271
|
-
* Gets task function worker usage statistics.
|
|
272
|
-
*
|
|
273
|
-
* @param name - The task function name.
|
|
274
|
-
* @returns The task function worker usage statistics if the task function worker usage statistics are initialized, `undefined` otherwise.
|
|
275
|
-
*/
|
|
276
|
-
readonly getTaskFunctionWorkerUsage: (name: string) => WorkerUsage | undefined;
|
|
277
|
-
}
|
package/lib/utility-types.d.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import type { EventLoopUtilization } from 'node:perf_hooks';
|
|
4
|
-
import type { MessagePort, TransferListItem } from 'node:worker_threads';
|
|
5
|
-
import type { KillBehavior } from './worker/worker-options';
|
|
6
|
-
/**
|
|
7
|
-
* Task error.
|
|
8
|
-
*
|
|
9
|
-
* @typeParam Data - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
|
|
10
|
-
*/
|
|
11
|
-
export interface TaskError<Data = unknown> {
|
|
12
|
-
/**
|
|
13
|
-
* Task name triggering the error.
|
|
14
|
-
*/
|
|
15
|
-
readonly name: string;
|
|
16
|
-
/**
|
|
17
|
-
* Error message.
|
|
18
|
-
*/
|
|
19
|
-
readonly message: string;
|
|
20
|
-
/**
|
|
21
|
-
* Data triggering the error.
|
|
22
|
-
*/
|
|
23
|
-
readonly data?: Data;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Task performance.
|
|
27
|
-
*
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export interface TaskPerformance {
|
|
31
|
-
/**
|
|
32
|
-
* Task name.
|
|
33
|
-
*/
|
|
34
|
-
readonly name: string;
|
|
35
|
-
/**
|
|
36
|
-
* Task performance timestamp.
|
|
37
|
-
*/
|
|
38
|
-
readonly timestamp: number;
|
|
39
|
-
/**
|
|
40
|
-
* Task runtime.
|
|
41
|
-
*/
|
|
42
|
-
readonly runTime?: number;
|
|
43
|
-
/**
|
|
44
|
-
* Task event loop utilization.
|
|
45
|
-
*/
|
|
46
|
-
readonly elu?: EventLoopUtilization;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Performance statistics computation.
|
|
50
|
-
*
|
|
51
|
-
* @internal
|
|
52
|
-
*/
|
|
53
|
-
export interface WorkerStatistics {
|
|
54
|
-
runTime: boolean;
|
|
55
|
-
elu: boolean;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Message object that is passed as a task between main worker and worker.
|
|
59
|
-
*
|
|
60
|
-
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
export interface Task<Data = unknown> {
|
|
64
|
-
/**
|
|
65
|
-
* Worker id.
|
|
66
|
-
*/
|
|
67
|
-
readonly workerId: number;
|
|
68
|
-
/**
|
|
69
|
-
* Task name.
|
|
70
|
-
*/
|
|
71
|
-
readonly name?: string;
|
|
72
|
-
/**
|
|
73
|
-
* Task input data that will be passed to the worker.
|
|
74
|
-
*/
|
|
75
|
-
readonly data?: Data;
|
|
76
|
-
/**
|
|
77
|
-
* Array of transferable objects.
|
|
78
|
-
*/
|
|
79
|
-
readonly transferList?: TransferListItem[];
|
|
80
|
-
/**
|
|
81
|
-
* Timestamp.
|
|
82
|
-
*/
|
|
83
|
-
readonly timestamp?: number;
|
|
84
|
-
/**
|
|
85
|
-
* Task UUID.
|
|
86
|
-
*/
|
|
87
|
-
readonly taskId?: string;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Message object that is passed between main worker and worker.
|
|
91
|
-
*
|
|
92
|
-
* @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
|
|
93
|
-
* @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
|
|
94
|
-
* @internal
|
|
95
|
-
*/
|
|
96
|
-
export interface MessageValue<Data = unknown, ErrorData = unknown> extends Task<Data> {
|
|
97
|
-
/**
|
|
98
|
-
* Kill code.
|
|
99
|
-
*/
|
|
100
|
-
readonly kill?: KillBehavior | true | 'success' | 'failure';
|
|
101
|
-
/**
|
|
102
|
-
* Task error.
|
|
103
|
-
*/
|
|
104
|
-
readonly taskError?: TaskError<ErrorData>;
|
|
105
|
-
/**
|
|
106
|
-
* Task performance.
|
|
107
|
-
*/
|
|
108
|
-
readonly taskPerformance?: TaskPerformance;
|
|
109
|
-
/**
|
|
110
|
-
* Task function names.
|
|
111
|
-
*/
|
|
112
|
-
readonly taskFunctions?: string[];
|
|
113
|
-
/**
|
|
114
|
-
* Whether the worker computes the given statistics or not.
|
|
115
|
-
*/
|
|
116
|
-
readonly statistics?: WorkerStatistics;
|
|
117
|
-
/**
|
|
118
|
-
* Whether the worker is ready or not.
|
|
119
|
-
*/
|
|
120
|
-
readonly ready?: boolean;
|
|
121
|
-
/**
|
|
122
|
-
* Whether the worker starts or stops its activity check.
|
|
123
|
-
*/
|
|
124
|
-
readonly checkActive?: boolean;
|
|
125
|
-
/**
|
|
126
|
-
* Message port.
|
|
127
|
-
*/
|
|
128
|
-
readonly port?: MessagePort;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* An object holding the task execution response promise resolve/reject callbacks.
|
|
132
|
-
*
|
|
133
|
-
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
134
|
-
* @internal
|
|
135
|
-
*/
|
|
136
|
-
export interface PromiseResponseWrapper<Response = unknown> {
|
|
137
|
-
/**
|
|
138
|
-
* Resolve callback to fulfill the promise.
|
|
139
|
-
*/
|
|
140
|
-
readonly resolve: (value: Response | PromiseLike<Response>) => void;
|
|
141
|
-
/**
|
|
142
|
-
* Reject callback to reject the promise.
|
|
143
|
-
*/
|
|
144
|
-
readonly reject: (reason?: unknown) => void;
|
|
145
|
-
/**
|
|
146
|
-
* The worker node key executing the task.
|
|
147
|
-
*/
|
|
148
|
-
readonly workerNodeKey: number;
|
|
149
|
-
}
|
|
150
|
-
export type Writable<T> = {
|
|
151
|
-
-readonly [P in keyof T]: T[P];
|
|
152
|
-
};
|
package/lib/utils.d.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import type { MeasurementStatisticsRequirements, WorkerChoiceStrategyOptions } from './pools/selection-strategies/selection-strategies-types';
|
|
2
|
-
import { type IWorker, type MeasurementStatistics, type WorkerType } from './pools/worker';
|
|
3
|
-
/**
|
|
4
|
-
* Default task name.
|
|
5
|
-
*/
|
|
6
|
-
export declare const DEFAULT_TASK_NAME = "default";
|
|
7
|
-
/**
|
|
8
|
-
* An intentional empty function.
|
|
9
|
-
*/
|
|
10
|
-
export declare const EMPTY_FUNCTION: () => void;
|
|
11
|
-
/**
|
|
12
|
-
* Default worker choice strategy options.
|
|
13
|
-
*/
|
|
14
|
-
export declare const DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS: WorkerChoiceStrategyOptions;
|
|
15
|
-
/**
|
|
16
|
-
* Default measurement statistics requirements.
|
|
17
|
-
*/
|
|
18
|
-
export declare const DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS: MeasurementStatisticsRequirements;
|
|
19
|
-
/**
|
|
20
|
-
* Returns safe host OS optimized estimate of the default amount of parallelism a pool should use.
|
|
21
|
-
* Always returns a value greater than zero.
|
|
22
|
-
*
|
|
23
|
-
* @returns The host OS optimized maximum pool size.
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export declare const availableParallelism: () => number;
|
|
27
|
-
/**
|
|
28
|
-
* Returns the worker type of the given worker.
|
|
29
|
-
*
|
|
30
|
-
* @param worker - The worker to get the type of.
|
|
31
|
-
* @returns The worker type of the given worker.
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
export declare const getWorkerType: <Worker_1 extends IWorker>(worker: Worker_1) => WorkerType | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* Returns the worker id of the given worker.
|
|
37
|
-
*
|
|
38
|
-
* @param worker - The worker to get the id of.
|
|
39
|
-
* @returns The worker id of the given worker.
|
|
40
|
-
* @internal
|
|
41
|
-
*/
|
|
42
|
-
export declare const getWorkerId: <Worker_1 extends IWorker>(worker: Worker_1) => number | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Sleeps for the given amount of milliseconds.
|
|
45
|
-
*
|
|
46
|
-
* @param ms - The amount of milliseconds to sleep.
|
|
47
|
-
* @returns A promise that resolves after the given amount of milliseconds.
|
|
48
|
-
*/
|
|
49
|
-
export declare const sleep: (ms: number) => Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Computes the retry delay in milliseconds using an exponential back off algorithm.
|
|
52
|
-
*
|
|
53
|
-
* @param retryNumber - The number of retries that have already been attempted
|
|
54
|
-
* @param delayFactor - The base delay factor in milliseconds
|
|
55
|
-
* @returns Delay in milliseconds
|
|
56
|
-
* @internal
|
|
57
|
-
*/
|
|
58
|
-
export declare const exponentialDelay: (retryNumber?: number, delayFactor?: number) => number;
|
|
59
|
-
/**
|
|
60
|
-
* Computes the average of the given data set.
|
|
61
|
-
*
|
|
62
|
-
* @param dataSet - Data set.
|
|
63
|
-
* @returns The average of the given data set.
|
|
64
|
-
* @internal
|
|
65
|
-
*/
|
|
66
|
-
export declare const average: (dataSet: number[]) => number;
|
|
67
|
-
/**
|
|
68
|
-
* Computes the median of the given data set.
|
|
69
|
-
*
|
|
70
|
-
* @param dataSet - Data set.
|
|
71
|
-
* @returns The median of the given data set.
|
|
72
|
-
* @internal
|
|
73
|
-
*/
|
|
74
|
-
export declare const median: (dataSet: number[]) => number;
|
|
75
|
-
/**
|
|
76
|
-
* Rounds the given number to the given scale.
|
|
77
|
-
* The rounding is done using the "round half away from zero" method.
|
|
78
|
-
*
|
|
79
|
-
* @param num - The number to round.
|
|
80
|
-
* @param scale - The scale to round to.
|
|
81
|
-
* @returns The rounded number.
|
|
82
|
-
*/
|
|
83
|
-
export declare const round: (num: number, scale?: number) => number;
|
|
84
|
-
/**
|
|
85
|
-
* Is the given object a plain object?
|
|
86
|
-
*
|
|
87
|
-
* @param obj - The object to check.
|
|
88
|
-
* @returns `true` if the given object is a plain object, `false` otherwise.
|
|
89
|
-
*/
|
|
90
|
-
export declare const isPlainObject: (obj: unknown) => boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Detects whether the given value is a kill behavior or not.
|
|
93
|
-
*
|
|
94
|
-
* @typeParam KB - Which specific KillBehavior type to test against.
|
|
95
|
-
* @param killBehavior - Which kind of kill behavior to detect.
|
|
96
|
-
* @param value - Any value.
|
|
97
|
-
* @returns `true` if `value` was strictly equals to `killBehavior`, otherwise `false`.
|
|
98
|
-
* @internal
|
|
99
|
-
*/
|
|
100
|
-
export declare const isKillBehavior: <KB extends "SOFT" | "HARD">(killBehavior: KB, value: unknown) => value is KB;
|
|
101
|
-
/**
|
|
102
|
-
* Detects whether the given value is an asynchronous function or not.
|
|
103
|
-
*
|
|
104
|
-
* @param fn - Any value.
|
|
105
|
-
* @returns `true` if `fn` was an asynchronous function, otherwise `false`.
|
|
106
|
-
*/
|
|
107
|
-
export declare const isAsyncFunction: (fn: unknown) => fn is (...args: unknown[]) => Promise<unknown>;
|
|
108
|
-
/**
|
|
109
|
-
* Updates the given measurement statistics.
|
|
110
|
-
*
|
|
111
|
-
* @param measurementStatistics - The measurement statistics to update.
|
|
112
|
-
* @param measurementRequirements - The measurement statistics requirements.
|
|
113
|
-
* @param measurementValue - The measurement value.
|
|
114
|
-
* @param numberOfMeasurements - The number of measurements.
|
|
115
|
-
* @internal
|
|
116
|
-
*/
|
|
117
|
-
export declare const updateMeasurementStatistics: (measurementStatistics: MeasurementStatistics, measurementRequirements: MeasurementStatisticsRequirements, measurementValue: number) => void;
|
|
118
|
-
/**
|
|
119
|
-
* Generate a cryptographically secure random number in the [0,1[ range
|
|
120
|
-
*
|
|
121
|
-
* @returns A number in the [0,1[ range
|
|
122
|
-
*/
|
|
123
|
-
export declare const secureRandom: () => number;
|