poolifier 4.0.13 → 4.0.14
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/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +21 -192
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/package.json +14 -19
package/lib/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { ClusterSettings, Worker } from 'node:cluster';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Circular buffer designed for positive numbers.
|
|
10
|
-
*
|
|
11
10
|
* @internal
|
|
12
11
|
*/
|
|
13
12
|
declare class CircularBuffer {
|
|
@@ -23,37 +22,31 @@ declare class CircularBuffer {
|
|
|
23
22
|
constructor(size?: number);
|
|
24
23
|
/**
|
|
25
24
|
* Checks whether the buffer is empty.
|
|
26
|
-
*
|
|
27
25
|
* @returns Whether the buffer is empty.
|
|
28
26
|
*/
|
|
29
27
|
empty(): boolean;
|
|
30
28
|
/**
|
|
31
29
|
* Checks whether the buffer is full.
|
|
32
|
-
*
|
|
33
30
|
* @returns Whether the buffer is full.
|
|
34
31
|
*/
|
|
35
32
|
full(): boolean;
|
|
36
33
|
/**
|
|
37
34
|
* Puts number into buffer.
|
|
38
|
-
*
|
|
39
35
|
* @param number - Number to put into buffer.
|
|
40
36
|
*/
|
|
41
37
|
put(number: number): void;
|
|
42
38
|
/**
|
|
43
39
|
* Gets number from buffer.
|
|
44
|
-
*
|
|
45
40
|
* @returns Number from buffer.
|
|
46
41
|
*/
|
|
47
42
|
get(): number | undefined;
|
|
48
43
|
/**
|
|
49
44
|
* Returns buffer as numbers' array.
|
|
50
|
-
*
|
|
51
45
|
* @returns Numbers' array.
|
|
52
46
|
*/
|
|
53
47
|
toArray(): number[];
|
|
54
48
|
/**
|
|
55
49
|
* Checks the buffer size.
|
|
56
|
-
*
|
|
57
50
|
* @param size - Buffer size.
|
|
58
51
|
*/
|
|
59
52
|
private checkSize;
|
|
@@ -61,7 +54,6 @@ declare class CircularBuffer {
|
|
|
61
54
|
|
|
62
55
|
/**
|
|
63
56
|
* Fixed priority queue node.
|
|
64
|
-
*
|
|
65
57
|
* @typeParam T - Type of priority queue node data.
|
|
66
58
|
* @internal
|
|
67
59
|
*/
|
|
@@ -71,7 +63,6 @@ interface FixedPriorityQueueNode<T> {
|
|
|
71
63
|
}
|
|
72
64
|
/**
|
|
73
65
|
* Fixed priority queue.
|
|
74
|
-
*
|
|
75
66
|
* @typeParam T - Type of fixed priority queue data.
|
|
76
67
|
* @internal
|
|
77
68
|
*/
|
|
@@ -86,7 +77,6 @@ declare class FixedPriorityQueue<T> {
|
|
|
86
77
|
enablePriority: boolean;
|
|
87
78
|
/**
|
|
88
79
|
* Constructs a fixed priority queue.
|
|
89
|
-
*
|
|
90
80
|
* @param size - Fixed priority queue size. @defaultValue defaultQueueSize
|
|
91
81
|
* @param enablePriority - Whether to enable priority. @defaultValue false
|
|
92
82
|
* @returns FixedPriorityQueue.
|
|
@@ -94,19 +84,16 @@ declare class FixedPriorityQueue<T> {
|
|
|
94
84
|
constructor(size?: number, enablePriority?: boolean);
|
|
95
85
|
/**
|
|
96
86
|
* Checks if the fixed priority queue is empty.
|
|
97
|
-
*
|
|
98
87
|
* @returns `true` if the fixed priority queue is empty, `false` otherwise.
|
|
99
88
|
*/
|
|
100
89
|
empty(): boolean;
|
|
101
90
|
/**
|
|
102
91
|
* Checks if the fixed priority queue is full.
|
|
103
|
-
*
|
|
104
92
|
* @returns `true` if the fixed priority queue is full, `false` otherwise.
|
|
105
93
|
*/
|
|
106
94
|
full(): boolean;
|
|
107
95
|
/**
|
|
108
96
|
* Enqueue data into the fixed priority queue.
|
|
109
|
-
*
|
|
110
97
|
* @param data - Data to enqueue.
|
|
111
98
|
* @param priority - Priority of the data. Lower values have higher priority.
|
|
112
99
|
* @returns The new size of the priority queue.
|
|
@@ -115,14 +102,12 @@ declare class FixedPriorityQueue<T> {
|
|
|
115
102
|
enqueue(data: T, priority?: number): number;
|
|
116
103
|
/**
|
|
117
104
|
* Gets data from the fixed priority queue.
|
|
118
|
-
*
|
|
119
105
|
* @param index - The index of the data to get.
|
|
120
106
|
* @returns The data at the index or `undefined` if the fixed priority queue is empty or the index is out of bounds.
|
|
121
107
|
*/
|
|
122
108
|
get(index: number): T | undefined;
|
|
123
109
|
/**
|
|
124
110
|
* Dequeue data from the fixed priority queue.
|
|
125
|
-
*
|
|
126
111
|
* @returns The dequeued data or `undefined` if the priority queue is empty.
|
|
127
112
|
*/
|
|
128
113
|
dequeue(): T | undefined;
|
|
@@ -132,14 +117,12 @@ declare class FixedPriorityQueue<T> {
|
|
|
132
117
|
clear(): void;
|
|
133
118
|
/**
|
|
134
119
|
* Returns an iterator for the fixed priority queue.
|
|
135
|
-
*
|
|
136
120
|
* @returns An iterator for the fixed priority queue.
|
|
137
121
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
|
|
138
122
|
*/
|
|
139
123
|
[Symbol.iterator](): Iterator<T>;
|
|
140
124
|
/**
|
|
141
125
|
* Checks the queue size.
|
|
142
|
-
*
|
|
143
126
|
* @param size - Queue size.
|
|
144
127
|
*/
|
|
145
128
|
private checkSize;
|
|
@@ -192,33 +175,28 @@ interface WorkerChoiceStrategyOptions {
|
|
|
192
175
|
readonly measurement?: Measurement;
|
|
193
176
|
/**
|
|
194
177
|
* Runtime options.
|
|
195
|
-
*
|
|
196
178
|
* @defaultValue \{ median: false \}
|
|
197
179
|
*/
|
|
198
180
|
readonly runTime?: MeasurementOptions;
|
|
199
181
|
/**
|
|
200
182
|
* Wait time options.
|
|
201
|
-
*
|
|
202
183
|
* @defaultValue \{ median: false \}
|
|
203
184
|
*/
|
|
204
185
|
readonly waitTime?: MeasurementOptions;
|
|
205
186
|
/**
|
|
206
187
|
* Event loop utilization options.
|
|
207
|
-
*
|
|
208
188
|
* @defaultValue \{ median: false \}
|
|
209
189
|
*/
|
|
210
190
|
readonly elu?: MeasurementOptions;
|
|
211
191
|
/**
|
|
212
192
|
* Worker weights to use for weighted round robin worker selection strategies.
|
|
213
193
|
* A weight is tasks maximum execution time in milliseconds for a worker node.
|
|
214
|
-
*
|
|
215
194
|
* @defaultValue Weights computed automatically given the CPU performance.
|
|
216
195
|
*/
|
|
217
196
|
weights?: Record<number, number>;
|
|
218
197
|
}
|
|
219
198
|
/**
|
|
220
199
|
* Measurement statistics requirements.
|
|
221
|
-
*
|
|
222
200
|
* @internal
|
|
223
201
|
*/
|
|
224
202
|
interface MeasurementStatisticsRequirements {
|
|
@@ -237,7 +215,6 @@ interface MeasurementStatisticsRequirements {
|
|
|
237
215
|
}
|
|
238
216
|
/**
|
|
239
217
|
* Pool worker node worker usage statistics requirements.
|
|
240
|
-
*
|
|
241
218
|
* @internal
|
|
242
219
|
*/
|
|
243
220
|
interface TaskStatisticsRequirements {
|
|
@@ -256,7 +233,6 @@ interface TaskStatisticsRequirements {
|
|
|
256
233
|
}
|
|
257
234
|
/**
|
|
258
235
|
* Strategy policy.
|
|
259
|
-
*
|
|
260
236
|
* @internal
|
|
261
237
|
*/
|
|
262
238
|
interface StrategyPolicy {
|
|
@@ -271,7 +247,6 @@ interface StrategyPolicy {
|
|
|
271
247
|
}
|
|
272
248
|
/**
|
|
273
249
|
* Worker choice strategy interface.
|
|
274
|
-
*
|
|
275
250
|
* @internal
|
|
276
251
|
*/
|
|
277
252
|
interface IWorkerChoiceStrategy {
|
|
@@ -285,14 +260,12 @@ interface IWorkerChoiceStrategy {
|
|
|
285
260
|
readonly taskStatisticsRequirements: TaskStatisticsRequirements;
|
|
286
261
|
/**
|
|
287
262
|
* Resets strategy internals.
|
|
288
|
-
*
|
|
289
263
|
* @returns `true` if the reset is successful, `false` otherwise.
|
|
290
264
|
*/
|
|
291
265
|
readonly reset: () => boolean;
|
|
292
266
|
/**
|
|
293
267
|
* Updates the worker node key strategy internals.
|
|
294
268
|
* This is called after a task has been executed on a worker node.
|
|
295
|
-
*
|
|
296
269
|
* @returns `true` if the update is successful, `false` otherwise.
|
|
297
270
|
*/
|
|
298
271
|
readonly update: (workerNodeKey: number) => boolean;
|
|
@@ -300,20 +273,17 @@ interface IWorkerChoiceStrategy {
|
|
|
300
273
|
* Chooses a worker node in the pool and returns its key.
|
|
301
274
|
* If no worker nodes are not eligible, `undefined` is returned.
|
|
302
275
|
* If `undefined` is returned, the caller retry.
|
|
303
|
-
*
|
|
304
276
|
* @returns The worker node key or `undefined`.
|
|
305
277
|
*/
|
|
306
278
|
readonly choose: () => number | undefined;
|
|
307
279
|
/**
|
|
308
280
|
* Removes the worker node key from strategy internals.
|
|
309
|
-
*
|
|
310
281
|
* @param workerNodeKey - The worker node key.
|
|
311
282
|
* @returns `true` if the worker node key is removed, `false` otherwise.
|
|
312
283
|
*/
|
|
313
284
|
readonly remove: (workerNodeKey: number) => boolean;
|
|
314
285
|
/**
|
|
315
286
|
* Sets the worker choice strategy options.
|
|
316
|
-
*
|
|
317
287
|
* @param opts - The worker choice strategy options.
|
|
318
288
|
*/
|
|
319
289
|
readonly setOptions: (opts: WorkerChoiceStrategyOptions | undefined) => void;
|
|
@@ -345,7 +315,6 @@ interface WorkerOptions {
|
|
|
345
315
|
* - HARD: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but the worker is stealing tasks or a task is executing or queued, then the worker will be deleted.
|
|
346
316
|
*
|
|
347
317
|
* This option only apply to the newly created workers.
|
|
348
|
-
*
|
|
349
318
|
* @defaultValue KillBehaviors.SOFT
|
|
350
319
|
*/
|
|
351
320
|
killBehavior?: KillBehavior;
|
|
@@ -356,15 +325,13 @@ interface WorkerOptions {
|
|
|
356
325
|
* The last active time of your worker will be updated when it terminates a task.
|
|
357
326
|
*
|
|
358
327
|
* - If `killBehavior` is set to `KillBehaviors.HARD` this value represents also the timeout for the tasks that you submit to the pool,
|
|
359
|
-
*
|
|
328
|
+
* when this timeout expires your tasks is interrupted before completion and removed. The worker is killed if is not part of the minimum size of the pool.
|
|
360
329
|
* - If `killBehavior` is set to `KillBehaviors.SOFT` your tasks have no timeout and your workers will not be terminated until your task is completed.
|
|
361
|
-
*
|
|
362
330
|
* @defaultValue 60000
|
|
363
331
|
*/
|
|
364
332
|
maxInactiveTime?: number;
|
|
365
333
|
/**
|
|
366
334
|
* The function to call when a worker is killed.
|
|
367
|
-
*
|
|
368
335
|
* @defaultValue `() => {}`
|
|
369
336
|
*/
|
|
370
337
|
killHandler?: KillHandler;
|
|
@@ -372,7 +339,6 @@ interface WorkerOptions {
|
|
|
372
339
|
|
|
373
340
|
/**
|
|
374
341
|
* Worker error.
|
|
375
|
-
*
|
|
376
342
|
* @typeParam Data - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
|
|
377
343
|
*/
|
|
378
344
|
interface WorkerError<Data = unknown> {
|
|
@@ -391,7 +357,6 @@ interface WorkerError<Data = unknown> {
|
|
|
391
357
|
}
|
|
392
358
|
/**
|
|
393
359
|
* Task performance.
|
|
394
|
-
*
|
|
395
360
|
* @internal
|
|
396
361
|
*/
|
|
397
362
|
interface TaskPerformance {
|
|
@@ -414,7 +379,6 @@ interface TaskPerformance {
|
|
|
414
379
|
}
|
|
415
380
|
/**
|
|
416
381
|
* Worker task performance statistics computation settings.
|
|
417
|
-
*
|
|
418
382
|
* @internal
|
|
419
383
|
*/
|
|
420
384
|
interface WorkerStatistics {
|
|
@@ -446,7 +410,6 @@ interface TaskFunctionProperties {
|
|
|
446
410
|
}
|
|
447
411
|
/**
|
|
448
412
|
* Message object that is passed as a task between main worker and worker.
|
|
449
|
-
*
|
|
450
413
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
451
414
|
* @internal
|
|
452
415
|
*/
|
|
@@ -461,7 +424,6 @@ interface Task<Data = unknown> {
|
|
|
461
424
|
readonly data?: Data;
|
|
462
425
|
/**
|
|
463
426
|
* Task priority. Lower values have higher priority.
|
|
464
|
-
*
|
|
465
427
|
* @defaultValue 0
|
|
466
428
|
*/
|
|
467
429
|
readonly priority?: number;
|
|
@@ -484,7 +446,6 @@ interface Task<Data = unknown> {
|
|
|
484
446
|
}
|
|
485
447
|
/**
|
|
486
448
|
* Message object that is passed between main worker and worker.
|
|
487
|
-
*
|
|
488
449
|
* @typeParam Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
|
|
489
450
|
* @typeParam ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
|
|
490
451
|
* @internal
|
|
@@ -548,7 +509,6 @@ interface MessageValue<Data = unknown, ErrorData = unknown> extends Task<Data> {
|
|
|
548
509
|
}
|
|
549
510
|
/**
|
|
550
511
|
* An object holding the task execution response promise resolve/reject callbacks.
|
|
551
|
-
*
|
|
552
512
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
553
513
|
* @internal
|
|
554
514
|
*/
|
|
@@ -576,10 +536,8 @@ type Writable<T> = {
|
|
|
576
536
|
|
|
577
537
|
/**
|
|
578
538
|
* Task synchronous function that can be executed.
|
|
579
|
-
*
|
|
580
539
|
* @param data - Data sent to the worker.
|
|
581
540
|
* @returns Execution response.
|
|
582
|
-
*
|
|
583
541
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
584
542
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
585
543
|
*/
|
|
@@ -587,10 +545,8 @@ type TaskSyncFunction<Data = unknown, Response = unknown> = (data?: Data) => Res
|
|
|
587
545
|
/**
|
|
588
546
|
* Task asynchronous function that can be executed.
|
|
589
547
|
* This function must return a promise.
|
|
590
|
-
*
|
|
591
548
|
* @param data - Data sent to the worker.
|
|
592
549
|
* @returns Execution response promise.
|
|
593
|
-
*
|
|
594
550
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
595
551
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
596
552
|
*/
|
|
@@ -598,14 +554,12 @@ type TaskAsyncFunction<Data = unknown, Response = unknown> = (data?: Data) => Pr
|
|
|
598
554
|
/**
|
|
599
555
|
* Task function that can be executed.
|
|
600
556
|
* This function can be synchronous or asynchronous.
|
|
601
|
-
*
|
|
602
557
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
603
558
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
604
559
|
*/
|
|
605
560
|
type TaskFunction<Data = unknown, Response = unknown> = TaskSyncFunction<Data, Response> | TaskAsyncFunction<Data, Response>;
|
|
606
561
|
/**
|
|
607
562
|
* Task function object.
|
|
608
|
-
*
|
|
609
563
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
610
564
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
611
565
|
*/
|
|
@@ -627,7 +581,6 @@ interface TaskFunctionObject<Data = unknown, Response = unknown> {
|
|
|
627
581
|
* Tasks functions that can be executed.
|
|
628
582
|
* The key is the name of the task function or task function object.
|
|
629
583
|
* The value is the task function or task function object.
|
|
630
|
-
*
|
|
631
584
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
632
585
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
633
586
|
*/
|
|
@@ -642,37 +595,31 @@ interface TaskFunctionOperationResult {
|
|
|
642
595
|
|
|
643
596
|
/**
|
|
644
597
|
* Callback invoked when the worker has started successfully.
|
|
645
|
-
*
|
|
646
598
|
* @typeParam Worker - Type of worker.
|
|
647
599
|
*/
|
|
648
600
|
type OnlineHandler<Worker extends IWorker> = (this: Worker) => void;
|
|
649
601
|
/**
|
|
650
602
|
* Callback invoked if the worker has received a message.
|
|
651
|
-
*
|
|
652
603
|
* @typeParam Worker - Type of worker.
|
|
653
604
|
*/
|
|
654
605
|
type MessageHandler<Worker extends IWorker> = (this: Worker, message: unknown) => void;
|
|
655
606
|
/**
|
|
656
607
|
* Callback invoked if the worker raised an error.
|
|
657
|
-
*
|
|
658
608
|
* @typeParam Worker - Type of worker.
|
|
659
609
|
*/
|
|
660
610
|
type ErrorHandler<Worker extends IWorker> = (this: Worker, error: Error) => void;
|
|
661
611
|
/**
|
|
662
612
|
* Callback invoked when the worker exits successfully.
|
|
663
|
-
*
|
|
664
613
|
* @typeParam Worker - Type of worker.
|
|
665
614
|
*/
|
|
666
615
|
type ExitHandler<Worker extends IWorker> = (this: Worker, exitCode: number) => void;
|
|
667
616
|
/**
|
|
668
617
|
* Worker event handler.
|
|
669
|
-
*
|
|
670
618
|
* @typeParam Worker - Type of worker.
|
|
671
619
|
*/
|
|
672
620
|
type EventHandler<Worker extends IWorker> = OnlineHandler<Worker> | MessageHandler<Worker> | ErrorHandler<Worker> | ExitHandler<Worker>;
|
|
673
621
|
/**
|
|
674
622
|
* Measurement statistics.
|
|
675
|
-
*
|
|
676
623
|
* @internal
|
|
677
624
|
*/
|
|
678
625
|
interface MeasurementStatistics {
|
|
@@ -703,7 +650,6 @@ interface MeasurementStatistics {
|
|
|
703
650
|
}
|
|
704
651
|
/**
|
|
705
652
|
* Event loop utilization measurement statistics.
|
|
706
|
-
*
|
|
707
653
|
* @internal
|
|
708
654
|
*/
|
|
709
655
|
interface EventLoopUtilizationMeasurementStatistics {
|
|
@@ -713,7 +659,6 @@ interface EventLoopUtilizationMeasurementStatistics {
|
|
|
713
659
|
}
|
|
714
660
|
/**
|
|
715
661
|
* Task statistics.
|
|
716
|
-
*
|
|
717
662
|
* @internal
|
|
718
663
|
*/
|
|
719
664
|
interface TaskStatistics {
|
|
@@ -759,7 +704,6 @@ declare const WorkerTypes: Readonly<{
|
|
|
759
704
|
type WorkerType = keyof typeof WorkerTypes;
|
|
760
705
|
/**
|
|
761
706
|
* Worker information.
|
|
762
|
-
*
|
|
763
707
|
* @internal
|
|
764
708
|
*/
|
|
765
709
|
interface WorkerInfo {
|
|
@@ -796,7 +740,6 @@ interface WorkerInfo {
|
|
|
796
740
|
}
|
|
797
741
|
/**
|
|
798
742
|
* Worker usage statistics.
|
|
799
|
-
*
|
|
800
743
|
* @internal
|
|
801
744
|
*/
|
|
802
745
|
interface WorkerUsage {
|
|
@@ -819,7 +762,6 @@ interface WorkerUsage {
|
|
|
819
762
|
}
|
|
820
763
|
/**
|
|
821
764
|
* Worker choice strategy data.
|
|
822
|
-
*
|
|
823
765
|
* @internal
|
|
824
766
|
*/
|
|
825
767
|
interface StrategyData {
|
|
@@ -839,14 +781,12 @@ interface IWorker extends EventEmitter {
|
|
|
839
781
|
readonly threadId?: number;
|
|
840
782
|
/**
|
|
841
783
|
* Registers an event handler.
|
|
842
|
-
*
|
|
843
784
|
* @param event - The event.
|
|
844
785
|
* @param handler - The event handler.
|
|
845
786
|
*/
|
|
846
787
|
readonly on: (event: string, handler: EventHandler<this>) => this;
|
|
847
788
|
/**
|
|
848
789
|
* Registers once an event handler.
|
|
849
|
-
*
|
|
850
790
|
* @param event - The event.
|
|
851
791
|
* @param handler - The event handler.
|
|
852
792
|
*/
|
|
@@ -873,7 +813,6 @@ interface IWorker extends EventEmitter {
|
|
|
873
813
|
}
|
|
874
814
|
/**
|
|
875
815
|
* Worker node options.
|
|
876
|
-
*
|
|
877
816
|
* @internal
|
|
878
817
|
*/
|
|
879
818
|
interface WorkerNodeOptions {
|
|
@@ -885,7 +824,6 @@ interface WorkerNodeOptions {
|
|
|
885
824
|
}
|
|
886
825
|
/**
|
|
887
826
|
* Worker node interface.
|
|
888
|
-
*
|
|
889
827
|
* @typeParam Worker - Type of worker.
|
|
890
828
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
891
829
|
* @internal
|
|
@@ -919,33 +857,28 @@ interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitt
|
|
|
919
857
|
tasksQueueBackPressureSize: number;
|
|
920
858
|
/**
|
|
921
859
|
* Sets tasks queue priority.
|
|
922
|
-
*
|
|
923
860
|
* @param enablePriority - Whether to enable tasks queue priority.
|
|
924
861
|
*/
|
|
925
862
|
readonly setTasksQueuePriority: (enablePriority: boolean) => void;
|
|
926
863
|
/**
|
|
927
864
|
* Tasks queue size.
|
|
928
|
-
*
|
|
929
865
|
* @returns The tasks queue size.
|
|
930
866
|
*/
|
|
931
867
|
readonly tasksQueueSize: () => number;
|
|
932
868
|
/**
|
|
933
869
|
* Enqueue task.
|
|
934
|
-
*
|
|
935
870
|
* @param task - The task to queue.
|
|
936
871
|
* @returns The tasks queue size.
|
|
937
872
|
*/
|
|
938
873
|
readonly enqueueTask: (task: Task<Data>) => number;
|
|
939
874
|
/**
|
|
940
875
|
* Dequeue task.
|
|
941
|
-
*
|
|
942
876
|
* @param bucket - The prioritized bucket to dequeue from. @defaultValue 0
|
|
943
877
|
* @returns The dequeued task.
|
|
944
878
|
*/
|
|
945
879
|
readonly dequeueTask: (bucket?: number) => Task<Data> | undefined;
|
|
946
880
|
/**
|
|
947
881
|
* Dequeue last prioritized task.
|
|
948
|
-
*
|
|
949
882
|
* @returns The dequeued task.
|
|
950
883
|
*/
|
|
951
884
|
readonly dequeueLastPrioritizedTask: () => Task<Data> | undefined;
|
|
@@ -955,7 +888,6 @@ interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitt
|
|
|
955
888
|
readonly clearTasksQueue: () => void;
|
|
956
889
|
/**
|
|
957
890
|
* Whether the worker node has back pressure (i.e. its tasks queue is full).
|
|
958
|
-
*
|
|
959
891
|
* @returns `true` if the worker node has back pressure, `false` otherwise.
|
|
960
892
|
*/
|
|
961
893
|
readonly hasBackPressure: () => boolean;
|
|
@@ -965,28 +897,24 @@ interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitt
|
|
|
965
897
|
readonly terminate: () => Promise<void>;
|
|
966
898
|
/**
|
|
967
899
|
* Registers a worker event handler.
|
|
968
|
-
*
|
|
969
900
|
* @param event - The event.
|
|
970
901
|
* @param handler - The event handler.
|
|
971
902
|
*/
|
|
972
903
|
readonly registerWorkerEventHandler: (event: string, handler: EventHandler<Worker>) => void;
|
|
973
904
|
/**
|
|
974
905
|
* Registers once a worker event handler.
|
|
975
|
-
*
|
|
976
906
|
* @param event - The event.
|
|
977
907
|
* @param handler - The event handler.
|
|
978
908
|
*/
|
|
979
909
|
readonly registerOnceWorkerEventHandler: (event: string, handler: EventHandler<Worker>) => void;
|
|
980
910
|
/**
|
|
981
911
|
* Gets task function worker usage statistics.
|
|
982
|
-
*
|
|
983
912
|
* @param name - The task function name.
|
|
984
913
|
* @returns The task function worker usage statistics if the task function worker usage statistics are initialized, `undefined` otherwise.
|
|
985
914
|
*/
|
|
986
915
|
readonly getTaskFunctionWorkerUsage: (name: string) => WorkerUsage | undefined;
|
|
987
916
|
/**
|
|
988
917
|
* Deletes task function worker usage statistics.
|
|
989
|
-
*
|
|
990
918
|
* @param name - The task function name.
|
|
991
919
|
* @returns `true` if the task function worker usage statistics were deleted, `false` otherwise.
|
|
992
920
|
*/
|
|
@@ -994,7 +922,6 @@ interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitt
|
|
|
994
922
|
}
|
|
995
923
|
/**
|
|
996
924
|
* Worker node event detail.
|
|
997
|
-
*
|
|
998
925
|
* @internal
|
|
999
926
|
*/
|
|
1000
927
|
interface WorkerNodeEventDetail {
|
|
@@ -1097,74 +1024,62 @@ interface PoolInfo {
|
|
|
1097
1024
|
interface TasksQueueOptions {
|
|
1098
1025
|
/**
|
|
1099
1026
|
* Maximum tasks queue size per worker node flagging it as back pressured.
|
|
1100
|
-
*
|
|
1101
1027
|
* @defaultValue (pool maximum size)^2
|
|
1102
1028
|
*/
|
|
1103
1029
|
readonly size?: number;
|
|
1104
1030
|
/**
|
|
1105
1031
|
* Maximum number of tasks that can be executed concurrently on a worker node.
|
|
1106
|
-
*
|
|
1107
1032
|
* @defaultValue 1
|
|
1108
1033
|
*/
|
|
1109
1034
|
readonly concurrency?: number;
|
|
1110
1035
|
/**
|
|
1111
1036
|
* Whether to enable task stealing on idle.
|
|
1112
|
-
*
|
|
1113
1037
|
* @defaultValue true
|
|
1114
1038
|
*/
|
|
1115
1039
|
readonly taskStealing?: boolean;
|
|
1116
1040
|
/**
|
|
1117
1041
|
* Whether to enable tasks stealing under back pressure.
|
|
1118
|
-
*
|
|
1119
1042
|
* @defaultValue false
|
|
1120
1043
|
*/
|
|
1121
1044
|
readonly tasksStealingOnBackPressure?: boolean;
|
|
1122
1045
|
/**
|
|
1123
1046
|
* Queued tasks finished timeout in milliseconds at worker node termination.
|
|
1124
|
-
*
|
|
1125
1047
|
* @defaultValue 2000
|
|
1126
1048
|
*/
|
|
1127
1049
|
readonly tasksFinishedTimeout?: number;
|
|
1128
1050
|
}
|
|
1129
1051
|
/**
|
|
1130
1052
|
* Options for a poolifier pool.
|
|
1131
|
-
*
|
|
1132
1053
|
* @typeParam Worker - Type of worker.
|
|
1133
1054
|
*/
|
|
1134
1055
|
interface PoolOptions<Worker extends IWorker> {
|
|
1135
1056
|
/**
|
|
1136
1057
|
* A function that will listen for online event on each worker.
|
|
1137
|
-
*
|
|
1138
1058
|
* @defaultValue `() => {}`
|
|
1139
1059
|
*/
|
|
1140
1060
|
onlineHandler?: OnlineHandler<Worker>;
|
|
1141
1061
|
/**
|
|
1142
1062
|
* A function that will listen for message event on each worker.
|
|
1143
|
-
*
|
|
1144
1063
|
* @defaultValue `() => {}`
|
|
1145
1064
|
*/
|
|
1146
1065
|
messageHandler?: MessageHandler<Worker>;
|
|
1147
1066
|
/**
|
|
1148
1067
|
* A function that will listen for error event on each worker.
|
|
1149
|
-
*
|
|
1150
1068
|
* @defaultValue `() => {}`
|
|
1151
1069
|
*/
|
|
1152
1070
|
errorHandler?: ErrorHandler<Worker>;
|
|
1153
1071
|
/**
|
|
1154
1072
|
* A function that will listen for exit event on each worker.
|
|
1155
|
-
*
|
|
1156
1073
|
* @defaultValue `() => {}`
|
|
1157
1074
|
*/
|
|
1158
1075
|
exitHandler?: ExitHandler<Worker>;
|
|
1159
1076
|
/**
|
|
1160
1077
|
* Whether to start the minimum number of workers at pool initialization.
|
|
1161
|
-
*
|
|
1162
1078
|
* @defaultValue true
|
|
1163
1079
|
*/
|
|
1164
1080
|
startWorkers?: boolean;
|
|
1165
1081
|
/**
|
|
1166
1082
|
* The default worker choice strategy to use in this pool.
|
|
1167
|
-
*
|
|
1168
1083
|
* @defaultValue WorkerChoiceStrategies.ROUND_ROBIN
|
|
1169
1084
|
*/
|
|
1170
1085
|
workerChoiceStrategy?: WorkerChoiceStrategy;
|
|
@@ -1178,13 +1093,11 @@ interface PoolOptions<Worker extends IWorker> {
|
|
|
1178
1093
|
restartWorkerOnError?: boolean;
|
|
1179
1094
|
/**
|
|
1180
1095
|
* Pool events integrated with async resource emission.
|
|
1181
|
-
*
|
|
1182
1096
|
* @defaultValue true
|
|
1183
1097
|
*/
|
|
1184
1098
|
enableEvents?: boolean;
|
|
1185
1099
|
/**
|
|
1186
1100
|
* Pool worker node tasks queue.
|
|
1187
|
-
*
|
|
1188
1101
|
* @defaultValue false
|
|
1189
1102
|
*/
|
|
1190
1103
|
enableTasksQueue?: boolean;
|
|
@@ -1194,26 +1107,22 @@ interface PoolOptions<Worker extends IWorker> {
|
|
|
1194
1107
|
tasksQueueOptions?: TasksQueueOptions;
|
|
1195
1108
|
/**
|
|
1196
1109
|
* Worker options.
|
|
1197
|
-
*
|
|
1198
1110
|
* @see https://nodejs.org/api/worker_threads.html#new-workerfilename-options
|
|
1199
1111
|
*/
|
|
1200
1112
|
workerOptions?: WorkerOptions$1;
|
|
1201
1113
|
/**
|
|
1202
1114
|
* Key/value pairs to add to worker process environment.
|
|
1203
|
-
*
|
|
1204
1115
|
* @see https://nodejs.org/api/cluster.html#cluster_cluster_fork_env
|
|
1205
1116
|
*/
|
|
1206
1117
|
env?: Record<string, unknown>;
|
|
1207
1118
|
/**
|
|
1208
1119
|
* Cluster settings.
|
|
1209
|
-
*
|
|
1210
1120
|
* @see https://nodejs.org/api/cluster.html#cluster_cluster_settings
|
|
1211
1121
|
*/
|
|
1212
1122
|
settings?: ClusterSettings;
|
|
1213
1123
|
}
|
|
1214
1124
|
/**
|
|
1215
1125
|
* Contract definition for a poolifier pool.
|
|
1216
|
-
*
|
|
1217
1126
|
* @typeParam Worker - Type of worker which manages this pool.
|
|
1218
1127
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1219
1128
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
@@ -1225,10 +1134,9 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1225
1134
|
readonly info: PoolInfo;
|
|
1226
1135
|
/**
|
|
1227
1136
|
* Pool worker nodes.
|
|
1228
|
-
*
|
|
1229
1137
|
* @internal
|
|
1230
1138
|
*/
|
|
1231
|
-
readonly workerNodes:
|
|
1139
|
+
readonly workerNodes: IWorkerNode<Worker, Data>[];
|
|
1232
1140
|
/**
|
|
1233
1141
|
* Pool event emitter integrated with async resource.
|
|
1234
1142
|
* The async tracking tooling identifier is `poolifier:<PoolType>-<WorkerType>-pool`.
|
|
@@ -1247,13 +1155,20 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1247
1155
|
readonly emitter?: EventEmitterAsyncResource;
|
|
1248
1156
|
/**
|
|
1249
1157
|
* Executes the specified function in the worker constructor with the task data input parameter.
|
|
1250
|
-
*
|
|
1251
1158
|
* @param data - The optional task input data for the specified task function. This can only be structured-cloneable data.
|
|
1252
1159
|
* @param name - The optional name of the task function to execute. If not specified, the default task function will be executed.
|
|
1253
1160
|
* @param transferList - An optional array of transferable objects to transfer ownership of. Ownership of the transferred objects is given to the chosen pool's worker_threads worker and they should not be used in the main thread afterwards.
|
|
1254
|
-
* @returns Promise that will be fulfilled when the task is completed.
|
|
1161
|
+
* @returns Promise with a task function response that will be fulfilled when the task is completed.
|
|
1255
1162
|
*/
|
|
1256
1163
|
readonly execute: (data?: Data, name?: string, transferList?: readonly TransferListItem[]) => Promise<Response>;
|
|
1164
|
+
/**
|
|
1165
|
+
* Executes the specified function in the worker constructor with the tasks data iterable input parameter.
|
|
1166
|
+
* @param data - The tasks iterable input data for the specified task function. This can only be an iterable of structured-cloneable data.
|
|
1167
|
+
* @param name - The optional name of the task function to execute. If not specified, the default task function will be executed.
|
|
1168
|
+
* @param transferList - An optional array of transferable objects to transfer ownership of. Ownership of the transferred objects is given to the chosen pool's worker_threads worker and they should not be used in the main thread afterwards.
|
|
1169
|
+
* @returns Promise with an array of task function responses that will be fulfilled when the tasks are completed.
|
|
1170
|
+
*/
|
|
1171
|
+
readonly mapExecute: (data: Iterable<Data>, name?: string, transferList?: readonly TransferListItem[]) => Promise<Response[]>;
|
|
1257
1172
|
/**
|
|
1258
1173
|
* Starts the minimum number of workers in this pool.
|
|
1259
1174
|
*/
|
|
@@ -1264,7 +1179,6 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1264
1179
|
readonly destroy: () => Promise<void>;
|
|
1265
1180
|
/**
|
|
1266
1181
|
* Whether the specified task function exists in this pool.
|
|
1267
|
-
*
|
|
1268
1182
|
* @param name - The name of the task function.
|
|
1269
1183
|
* @returns `true` if the task function exists, `false` otherwise.
|
|
1270
1184
|
*/
|
|
@@ -1272,7 +1186,6 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1272
1186
|
/**
|
|
1273
1187
|
* Adds a task function to this pool.
|
|
1274
1188
|
* If a task function with the same name already exists, it will be overwritten.
|
|
1275
|
-
*
|
|
1276
1189
|
* @param name - The name of the task function.
|
|
1277
1190
|
* @param fn - The task function.
|
|
1278
1191
|
* @returns `true` if the task function was added, `false` otherwise.
|
|
@@ -1282,48 +1195,41 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1282
1195
|
readonly addTaskFunction: (name: string, fn: TaskFunction<Data, Response> | TaskFunctionObject<Data, Response>) => Promise<boolean>;
|
|
1283
1196
|
/**
|
|
1284
1197
|
* Removes a task function from this pool.
|
|
1285
|
-
*
|
|
1286
1198
|
* @param name - The name of the task function.
|
|
1287
1199
|
* @returns `true` if the task function was removed, `false` otherwise.
|
|
1288
1200
|
*/
|
|
1289
1201
|
readonly removeTaskFunction: (name: string) => Promise<boolean>;
|
|
1290
1202
|
/**
|
|
1291
1203
|
* Lists the properties of task functions available in this pool.
|
|
1292
|
-
*
|
|
1293
1204
|
* @returns The properties of task functions available in this pool.
|
|
1294
1205
|
*/
|
|
1295
1206
|
readonly listTaskFunctionsProperties: () => TaskFunctionProperties[];
|
|
1296
1207
|
/**
|
|
1297
1208
|
* Sets the default task function in this pool.
|
|
1298
|
-
*
|
|
1299
1209
|
* @param name - The name of the task function.
|
|
1300
1210
|
* @returns `true` if the default task function was set, `false` otherwise.
|
|
1301
1211
|
*/
|
|
1302
1212
|
readonly setDefaultTaskFunction: (name: string) => Promise<boolean>;
|
|
1303
1213
|
/**
|
|
1304
1214
|
* Sets the default worker choice strategy in this pool.
|
|
1305
|
-
*
|
|
1306
1215
|
* @param workerChoiceStrategy - The default worker choice strategy.
|
|
1307
1216
|
* @param workerChoiceStrategyOptions - The worker choice strategy options.
|
|
1308
1217
|
*/
|
|
1309
1218
|
readonly setWorkerChoiceStrategy: (workerChoiceStrategy: WorkerChoiceStrategy, workerChoiceStrategyOptions?: WorkerChoiceStrategyOptions) => void;
|
|
1310
1219
|
/**
|
|
1311
1220
|
* Sets the worker choice strategy options in this pool.
|
|
1312
|
-
*
|
|
1313
1221
|
* @param workerChoiceStrategyOptions - The worker choice strategy options.
|
|
1314
1222
|
* @returns `true` if the worker choice strategy options were set, `false` otherwise.
|
|
1315
1223
|
*/
|
|
1316
1224
|
readonly setWorkerChoiceStrategyOptions: (workerChoiceStrategyOptions: WorkerChoiceStrategyOptions) => boolean;
|
|
1317
1225
|
/**
|
|
1318
1226
|
* Enables/disables the worker node tasks queue in this pool.
|
|
1319
|
-
*
|
|
1320
1227
|
* @param enable - Whether to enable or disable the worker node tasks queue.
|
|
1321
1228
|
* @param tasksQueueOptions - The worker node tasks queue options.
|
|
1322
1229
|
*/
|
|
1323
1230
|
readonly enableTasksQueue: (enable: boolean, tasksQueueOptions?: TasksQueueOptions) => void;
|
|
1324
1231
|
/**
|
|
1325
1232
|
* Sets the worker node tasks queue options in this pool.
|
|
1326
|
-
*
|
|
1327
1233
|
* @param tasksQueueOptions - The worker node tasks queue options.
|
|
1328
1234
|
*/
|
|
1329
1235
|
readonly setTasksQueueOptions: (tasksQueueOptions: TasksQueueOptions) => void;
|
|
@@ -1331,7 +1237,6 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1331
1237
|
|
|
1332
1238
|
/**
|
|
1333
1239
|
* The worker choice strategies context.
|
|
1334
|
-
*
|
|
1335
1240
|
* @typeParam Worker - Type of worker.
|
|
1336
1241
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1337
1242
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
@@ -1364,7 +1269,6 @@ declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unkno
|
|
|
1364
1269
|
private readonly retries;
|
|
1365
1270
|
/**
|
|
1366
1271
|
* Worker choice strategies context constructor.
|
|
1367
|
-
*
|
|
1368
1272
|
* @param pool - The pool instance.
|
|
1369
1273
|
* @param workerChoiceStrategies - The worker choice strategies. @defaultValue [WorkerChoiceStrategies.ROUND_ROBIN]
|
|
1370
1274
|
* @param opts - The worker choice strategy options.
|
|
@@ -1372,32 +1276,28 @@ declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unkno
|
|
|
1372
1276
|
constructor(pool: IPool<Worker, Data, Response>, workerChoiceStrategies?: WorkerChoiceStrategy[], opts?: WorkerChoiceStrategyOptions);
|
|
1373
1277
|
/**
|
|
1374
1278
|
* Gets the active worker choice strategies in the context policy.
|
|
1375
|
-
*
|
|
1376
1279
|
* @returns The strategies policy.
|
|
1377
1280
|
*/
|
|
1378
1281
|
getPolicy(): StrategyPolicy;
|
|
1379
1282
|
/**
|
|
1380
1283
|
* Gets the active worker choice strategies in the context task statistics requirements.
|
|
1381
|
-
*
|
|
1382
1284
|
* @returns The strategies task statistics requirements.
|
|
1383
1285
|
*/
|
|
1384
1286
|
getTaskStatisticsRequirements(): TaskStatisticsRequirements;
|
|
1385
1287
|
/**
|
|
1386
1288
|
* Sets the default worker choice strategy to use in the context.
|
|
1387
|
-
*
|
|
1388
1289
|
* @param workerChoiceStrategy - The default worker choice strategy to set.
|
|
1389
1290
|
* @param opts - The worker choice strategy options.
|
|
1390
1291
|
*/
|
|
1391
1292
|
setDefaultWorkerChoiceStrategy(workerChoiceStrategy: WorkerChoiceStrategy, opts?: WorkerChoiceStrategyOptions): void;
|
|
1392
1293
|
/**
|
|
1393
1294
|
* Updates the worker node key in the active worker choice strategies in the context internals.
|
|
1394
|
-
*
|
|
1295
|
+
* @param workerNodeKey - The worker node key.
|
|
1395
1296
|
* @returns `true` if the update is successful, `false` otherwise.
|
|
1396
1297
|
*/
|
|
1397
1298
|
update(workerNodeKey: number): boolean;
|
|
1398
1299
|
/**
|
|
1399
1300
|
* Executes the given worker choice strategy in the context algorithm.
|
|
1400
|
-
*
|
|
1401
1301
|
* @param workerChoiceStrategy - The worker choice strategy algorithm to execute. @defaultValue this.defaultWorkerChoiceStrategy
|
|
1402
1302
|
* @returns The key of the worker node.
|
|
1403
1303
|
* @throws {@link https://nodejs.org/api/errors.html#class-error} If after computed retries the worker node key is null or undefined.
|
|
@@ -1405,7 +1305,6 @@ declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unkno
|
|
|
1405
1305
|
execute(workerChoiceStrategy?: WorkerChoiceStrategy): number;
|
|
1406
1306
|
/**
|
|
1407
1307
|
* Executes the given worker choice strategy.
|
|
1408
|
-
*
|
|
1409
1308
|
* @param workerChoiceStrategy - The worker choice strategy.
|
|
1410
1309
|
* @returns The key of the worker node.
|
|
1411
1310
|
* @throws {@link https://nodejs.org/api/errors.html#class-error} If after computed retries the worker node key is null or undefined.
|
|
@@ -1413,35 +1312,31 @@ declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unkno
|
|
|
1413
1312
|
private executeStrategy;
|
|
1414
1313
|
/**
|
|
1415
1314
|
* Removes the worker node key from the active worker choice strategies in the context.
|
|
1416
|
-
*
|
|
1417
1315
|
* @param workerNodeKey - The worker node key.
|
|
1418
1316
|
* @returns `true` if the removal is successful, `false` otherwise.
|
|
1419
1317
|
*/
|
|
1420
1318
|
remove(workerNodeKey: number): boolean;
|
|
1421
1319
|
/**
|
|
1422
1320
|
* Sets the active worker choice strategies in the context options.
|
|
1423
|
-
*
|
|
1424
1321
|
* @param opts - The worker choice strategy options.
|
|
1425
1322
|
*/
|
|
1426
1323
|
setOptions(opts: WorkerChoiceStrategyOptions | undefined): void;
|
|
1427
1324
|
/**
|
|
1428
1325
|
* Synchronizes the active worker choice strategies in the context with the given worker choice strategies.
|
|
1429
|
-
*
|
|
1430
1326
|
* @param workerChoiceStrategies - The worker choice strategies to synchronize.
|
|
1431
1327
|
* @param opts - The worker choice strategy options.
|
|
1432
1328
|
*/
|
|
1433
1329
|
syncWorkerChoiceStrategies(workerChoiceStrategies: Set<WorkerChoiceStrategy>, opts?: WorkerChoiceStrategyOptions): void;
|
|
1434
1330
|
/**
|
|
1435
1331
|
* Adds a worker choice strategy to the context.
|
|
1436
|
-
*
|
|
1437
1332
|
* @param workerChoiceStrategy - The worker choice strategy to add.
|
|
1333
|
+
* @param pool - The pool instance.
|
|
1438
1334
|
* @param opts - The worker choice strategy options.
|
|
1439
1335
|
* @returns The worker choice strategies.
|
|
1440
1336
|
*/
|
|
1441
1337
|
private addWorkerChoiceStrategy;
|
|
1442
1338
|
/**
|
|
1443
1339
|
* Removes a worker choice strategy from the context.
|
|
1444
|
-
*
|
|
1445
1340
|
* @param workerChoiceStrategy - The worker choice strategy to remove.
|
|
1446
1341
|
* @returns `true` if the worker choice strategy is removed, `false` otherwise.
|
|
1447
1342
|
*/
|
|
@@ -1450,7 +1345,6 @@ declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unkno
|
|
|
1450
1345
|
|
|
1451
1346
|
/**
|
|
1452
1347
|
* Base class that implements some shared logic for all poolifier pools.
|
|
1453
|
-
*
|
|
1454
1348
|
* @typeParam Worker - Type of worker which manages this pool.
|
|
1455
1349
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1456
1350
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
@@ -1461,7 +1355,7 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1461
1355
|
protected readonly opts: PoolOptions<Worker>;
|
|
1462
1356
|
protected readonly maximumNumberOfWorkers?: number | undefined;
|
|
1463
1357
|
/** @inheritDoc */
|
|
1464
|
-
readonly workerNodes:
|
|
1358
|
+
readonly workerNodes: IWorkerNode<Worker, Data>[];
|
|
1465
1359
|
/** @inheritDoc */
|
|
1466
1360
|
emitter?: EventEmitterAsyncResource;
|
|
1467
1361
|
/**
|
|
@@ -1508,7 +1402,6 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1508
1402
|
private startTimestamp?;
|
|
1509
1403
|
/**
|
|
1510
1404
|
* Constructs a new poolifier pool.
|
|
1511
|
-
*
|
|
1512
1405
|
* @param minimumNumberOfWorkers - Minimum number of workers that this pool manages.
|
|
1513
1406
|
* @param filePath - Path to the worker file.
|
|
1514
1407
|
* @param opts - Options for the pool.
|
|
@@ -1532,7 +1425,6 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1532
1425
|
protected get empty(): boolean;
|
|
1533
1426
|
/**
|
|
1534
1427
|
* The approximate pool utilization.
|
|
1535
|
-
*
|
|
1536
1428
|
* @returns The pool utilization.
|
|
1537
1429
|
*/
|
|
1538
1430
|
private get utilization();
|
|
@@ -1548,14 +1440,12 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1548
1440
|
protected abstract get worker(): WorkerType;
|
|
1549
1441
|
/**
|
|
1550
1442
|
* Checks if the worker id sent in the received message from a worker is valid.
|
|
1551
|
-
*
|
|
1552
1443
|
* @param message - The received message.
|
|
1553
1444
|
* @throws {@link https://nodejs.org/api/errors.html#class-error} If the worker id is invalid.
|
|
1554
1445
|
*/
|
|
1555
1446
|
private checkMessageWorkerId;
|
|
1556
1447
|
/**
|
|
1557
1448
|
* Gets the worker node key given its worker id.
|
|
1558
|
-
*
|
|
1559
1449
|
* @param workerId - The worker id.
|
|
1560
1450
|
* @returns The worker node key if the worker id is found in the pool worker nodes, `-1` otherwise.
|
|
1561
1451
|
*/
|
|
@@ -1588,7 +1478,6 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1588
1478
|
protected abstract get busy(): boolean;
|
|
1589
1479
|
/**
|
|
1590
1480
|
* Whether worker nodes are executing concurrently their tasks quota or not.
|
|
1591
|
-
*
|
|
1592
1481
|
* @returns Worker nodes busyness boolean status.
|
|
1593
1482
|
*/
|
|
1594
1483
|
protected internalBusy(): boolean;
|
|
@@ -1605,14 +1494,12 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1605
1494
|
listTaskFunctionsProperties(): TaskFunctionProperties[];
|
|
1606
1495
|
/**
|
|
1607
1496
|
* Gets task function worker choice strategy, if any.
|
|
1608
|
-
*
|
|
1609
1497
|
* @param name - The task function name.
|
|
1610
1498
|
* @returns The task function worker choice strategy if the task function worker choice strategy is defined, `undefined` otherwise.
|
|
1611
1499
|
*/
|
|
1612
1500
|
private readonly getTaskFunctionWorkerChoiceStrategy;
|
|
1613
1501
|
/**
|
|
1614
1502
|
* Gets worker node task function worker choice strategy, if any.
|
|
1615
|
-
*
|
|
1616
1503
|
* @param workerNodeKey - The worker node key.
|
|
1617
1504
|
* @param name - The task function name.
|
|
1618
1505
|
* @returns The worker node task function worker choice strategy if the worker node task function worker choice strategy is defined, `undefined` otherwise.
|
|
@@ -1620,7 +1507,6 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1620
1507
|
private readonly getWorkerNodeTaskFunctionWorkerChoiceStrategy;
|
|
1621
1508
|
/**
|
|
1622
1509
|
* Gets worker node task function priority, if any.
|
|
1623
|
-
*
|
|
1624
1510
|
* @param workerNodeKey - The worker node key.
|
|
1625
1511
|
* @param name - The task function name.
|
|
1626
1512
|
* @returns The worker node task function priority if the worker node task function priority is defined, `undefined` otherwise.
|
|
@@ -1628,7 +1514,6 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1628
1514
|
private readonly getWorkerNodeTaskFunctionPriority;
|
|
1629
1515
|
/**
|
|
1630
1516
|
* Gets the worker choice strategies registered in this pool.
|
|
1631
|
-
*
|
|
1632
1517
|
* @returns The worker choice strategies.
|
|
1633
1518
|
*/
|
|
1634
1519
|
private readonly getWorkerChoiceStrategies;
|
|
@@ -1637,8 +1522,11 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1637
1522
|
private shallExecuteTask;
|
|
1638
1523
|
/** @inheritDoc */
|
|
1639
1524
|
execute(data?: Data, name?: string, transferList?: readonly TransferListItem[]): Promise<Response>;
|
|
1525
|
+
/** @inheritDoc */
|
|
1526
|
+
mapExecute(data: Iterable<Data>, name?: string, transferList?: readonly TransferListItem[]): Promise<Response[]>;
|
|
1640
1527
|
/**
|
|
1641
1528
|
* Starts the minimum number of workers.
|
|
1529
|
+
* @param initWorkerNodeUsage - Whether to initialize the worker node usage or not. @defaultValue false
|
|
1642
1530
|
*/
|
|
1643
1531
|
private startMinimumNumberOfWorkers;
|
|
1644
1532
|
/** @inheritdoc */
|
|
@@ -1648,27 +1536,22 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1648
1536
|
private sendKillMessageToWorker;
|
|
1649
1537
|
/**
|
|
1650
1538
|
* Terminates the worker node given its worker node key.
|
|
1651
|
-
*
|
|
1652
1539
|
* @param workerNodeKey - The worker node key.
|
|
1653
1540
|
*/
|
|
1654
1541
|
protected destroyWorkerNode(workerNodeKey: number): Promise<void>;
|
|
1655
1542
|
/**
|
|
1656
1543
|
* Setup hook to execute code before worker nodes are created in the abstract constructor.
|
|
1657
1544
|
* Can be overridden.
|
|
1658
|
-
*
|
|
1659
|
-
* @virtual
|
|
1660
1545
|
*/
|
|
1661
1546
|
protected setupHook(): void;
|
|
1662
1547
|
/**
|
|
1663
1548
|
* Returns whether the worker is the main worker or not.
|
|
1664
|
-
*
|
|
1665
1549
|
* @returns `true` if the worker is the main worker, `false` otherwise.
|
|
1666
1550
|
*/
|
|
1667
1551
|
protected abstract isMain(): boolean;
|
|
1668
1552
|
/**
|
|
1669
1553
|
* Hook executed before the worker task execution.
|
|
1670
1554
|
* Can be overridden.
|
|
1671
|
-
*
|
|
1672
1555
|
* @param workerNodeKey - The worker node key.
|
|
1673
1556
|
* @param task - The task to execute.
|
|
1674
1557
|
*/
|
|
@@ -1676,34 +1559,29 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1676
1559
|
/**
|
|
1677
1560
|
* Hook executed after the worker task execution.
|
|
1678
1561
|
* Can be overridden.
|
|
1679
|
-
*
|
|
1680
1562
|
* @param workerNodeKey - The worker node key.
|
|
1681
1563
|
* @param message - The received message.
|
|
1682
1564
|
*/
|
|
1683
1565
|
protected afterTaskExecutionHook(workerNodeKey: number, message: MessageValue<Response>): void;
|
|
1684
1566
|
/**
|
|
1685
1567
|
* Whether the worker node shall update its task function worker usage or not.
|
|
1686
|
-
*
|
|
1687
1568
|
* @param workerNodeKey - The worker node key.
|
|
1688
1569
|
* @returns `true` if the worker node shall update its task function worker usage, `false` otherwise.
|
|
1689
1570
|
*/
|
|
1690
1571
|
private shallUpdateTaskFunctionWorkerUsage;
|
|
1691
1572
|
/**
|
|
1692
1573
|
* Chooses a worker node for the next task.
|
|
1693
|
-
*
|
|
1694
1574
|
* @param name - The task function name.
|
|
1695
1575
|
* @returns The chosen worker node key.
|
|
1696
1576
|
*/
|
|
1697
1577
|
private chooseWorkerNode;
|
|
1698
1578
|
/**
|
|
1699
1579
|
* Conditions for dynamic worker creation.
|
|
1700
|
-
*
|
|
1701
1580
|
* @returns Whether to create a dynamic worker or not.
|
|
1702
1581
|
*/
|
|
1703
1582
|
protected abstract shallCreateDynamicWorker(): boolean;
|
|
1704
1583
|
/**
|
|
1705
1584
|
* Sends a message to worker given its worker node key.
|
|
1706
|
-
*
|
|
1707
1585
|
* @param workerNodeKey - The worker node key.
|
|
1708
1586
|
* @param message - The message.
|
|
1709
1587
|
* @param transferList - The optional array of transferable objects.
|
|
@@ -1711,39 +1589,33 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1711
1589
|
protected abstract sendToWorker(workerNodeKey: number, message: MessageValue<Data>, transferList?: readonly TransferListItem[]): void;
|
|
1712
1590
|
/**
|
|
1713
1591
|
* Initializes the worker node usage with sensible default values gathered during runtime.
|
|
1714
|
-
*
|
|
1715
1592
|
* @param workerNode - The worker node.
|
|
1716
1593
|
*/
|
|
1717
1594
|
private initWorkerNodeUsage;
|
|
1718
1595
|
/**
|
|
1719
1596
|
* Creates a new, completely set up worker node.
|
|
1720
|
-
*
|
|
1721
1597
|
* @returns New, completely set up worker node key.
|
|
1722
1598
|
*/
|
|
1723
1599
|
protected createAndSetupWorkerNode(): number;
|
|
1724
1600
|
/**
|
|
1725
1601
|
* Creates a new, completely set up dynamic worker node.
|
|
1726
|
-
*
|
|
1727
1602
|
* @returns New, completely set up dynamic worker node key.
|
|
1728
1603
|
*/
|
|
1729
1604
|
protected createAndSetupDynamicWorkerNode(): number;
|
|
1730
1605
|
/**
|
|
1731
1606
|
* Registers a listener callback on the worker given its worker node key.
|
|
1732
|
-
*
|
|
1733
1607
|
* @param workerNodeKey - The worker node key.
|
|
1734
1608
|
* @param listener - The message listener callback.
|
|
1735
1609
|
*/
|
|
1736
1610
|
protected abstract registerWorkerMessageListener<Message extends Data | Response>(workerNodeKey: number, listener: (message: MessageValue<Message>) => void): void;
|
|
1737
1611
|
/**
|
|
1738
1612
|
* Registers once a listener callback on the worker given its worker node key.
|
|
1739
|
-
*
|
|
1740
1613
|
* @param workerNodeKey - The worker node key.
|
|
1741
1614
|
* @param listener - The message listener callback.
|
|
1742
1615
|
*/
|
|
1743
1616
|
protected abstract registerOnceWorkerMessageListener<Message extends Data | Response>(workerNodeKey: number, listener: (message: MessageValue<Message>) => void): void;
|
|
1744
1617
|
/**
|
|
1745
1618
|
* Deregisters a listener callback on the worker given its worker node key.
|
|
1746
|
-
*
|
|
1747
1619
|
* @param workerNodeKey - The worker node key.
|
|
1748
1620
|
* @param listener - The message listener callback.
|
|
1749
1621
|
*/
|
|
@@ -1751,19 +1623,16 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1751
1623
|
/**
|
|
1752
1624
|
* Method hooked up after a worker node has been newly created.
|
|
1753
1625
|
* Can be overridden.
|
|
1754
|
-
*
|
|
1755
1626
|
* @param workerNodeKey - The newly created worker node key.
|
|
1756
1627
|
*/
|
|
1757
1628
|
protected afterWorkerNodeSetup(workerNodeKey: number): void;
|
|
1758
1629
|
/**
|
|
1759
1630
|
* Sends the startup message to worker given its worker node key.
|
|
1760
|
-
*
|
|
1761
1631
|
* @param workerNodeKey - The worker node key.
|
|
1762
1632
|
*/
|
|
1763
1633
|
protected abstract sendStartupMessageToWorker(workerNodeKey: number): void;
|
|
1764
1634
|
/**
|
|
1765
1635
|
* Sends the statistics message to worker given its worker node key.
|
|
1766
|
-
*
|
|
1767
1636
|
* @param workerNodeKey - The worker node key.
|
|
1768
1637
|
*/
|
|
1769
1638
|
private sendStatisticsMessageToWorker;
|
|
@@ -1779,6 +1648,7 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1779
1648
|
private setTasksQueuePriority;
|
|
1780
1649
|
/**
|
|
1781
1650
|
* This method is the message listener registered on each worker.
|
|
1651
|
+
* @param message - The message received from the worker.
|
|
1782
1652
|
*/
|
|
1783
1653
|
protected readonly workerMessageListener: (message: MessageValue<Response>) => void;
|
|
1784
1654
|
private checkAndEmitReadyEvent;
|
|
@@ -1792,7 +1662,6 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1792
1662
|
protected abstract checkAndEmitDynamicWorkerCreationEvents(): void;
|
|
1793
1663
|
/**
|
|
1794
1664
|
* Gets the worker information given its worker node key.
|
|
1795
|
-
*
|
|
1796
1665
|
* @param workerNodeKey - The worker node key.
|
|
1797
1666
|
* @returns The worker information.
|
|
1798
1667
|
*/
|
|
@@ -1800,13 +1669,11 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1800
1669
|
private getTasksQueuePriority;
|
|
1801
1670
|
/**
|
|
1802
1671
|
* Creates a worker node.
|
|
1803
|
-
*
|
|
1804
1672
|
* @returns The created worker node.
|
|
1805
1673
|
*/
|
|
1806
1674
|
private createWorkerNode;
|
|
1807
1675
|
/**
|
|
1808
1676
|
* Adds the given worker node in the pool worker nodes.
|
|
1809
|
-
*
|
|
1810
1677
|
* @param workerNode - The worker node.
|
|
1811
1678
|
* @returns The added worker node key.
|
|
1812
1679
|
* @throws {@link https://nodejs.org/api/errors.html#class-error} If the added worker node is not found.
|
|
@@ -1815,7 +1682,6 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1815
1682
|
private checkAndEmitEmptyEvent;
|
|
1816
1683
|
/**
|
|
1817
1684
|
* Removes the worker node from the pool worker nodes.
|
|
1818
|
-
*
|
|
1819
1685
|
* @param workerNode - The worker node.
|
|
1820
1686
|
*/
|
|
1821
1687
|
private removeWorkerNode;
|
|
@@ -1823,7 +1689,6 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1823
1689
|
private hasBackPressure;
|
|
1824
1690
|
/**
|
|
1825
1691
|
* Executes the given task on the worker given its worker node key.
|
|
1826
|
-
*
|
|
1827
1692
|
* @param workerNodeKey - The worker node key.
|
|
1828
1693
|
* @param task - The task to execute.
|
|
1829
1694
|
*/
|
|
@@ -1841,7 +1706,6 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1841
1706
|
type ClusterPoolOptions = PoolOptions<Worker>;
|
|
1842
1707
|
/**
|
|
1843
1708
|
* A cluster pool with a fixed number of workers.
|
|
1844
|
-
*
|
|
1845
1709
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1846
1710
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
1847
1711
|
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
|
|
@@ -1850,10 +1714,10 @@ type ClusterPoolOptions = PoolOptions<Worker>;
|
|
|
1850
1714
|
declare class FixedClusterPool<Data = unknown, Response = unknown> extends AbstractPool<Worker, Data, Response> {
|
|
1851
1715
|
/**
|
|
1852
1716
|
* Constructs a new poolifier fixed cluster pool.
|
|
1853
|
-
*
|
|
1854
1717
|
* @param numberOfWorkers - Number of workers for this pool.
|
|
1855
1718
|
* @param filePath - Path to an implementation of a `ClusterWorker` file, which can be relative or absolute.
|
|
1856
1719
|
* @param opts - Options for this fixed cluster pool.
|
|
1720
|
+
* @param maximumNumberOfWorkers - The maximum number of workers for this pool.
|
|
1857
1721
|
*/
|
|
1858
1722
|
constructor(numberOfWorkers: number, filePath: string, opts?: ClusterPoolOptions, maximumNumberOfWorkers?: number);
|
|
1859
1723
|
/** @inheritDoc */
|
|
@@ -1887,7 +1751,6 @@ declare class FixedClusterPool<Data = unknown, Response = unknown> extends Abstr
|
|
|
1887
1751
|
*
|
|
1888
1752
|
* This cluster pool creates new workers when the others are busy, up to the maximum number of workers.
|
|
1889
1753
|
* When the maximum number of workers is reached and workers are busy, an event is emitted. If you want to listen to this event, use the pool's `emitter`.
|
|
1890
|
-
*
|
|
1891
1754
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1892
1755
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
1893
1756
|
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
|
|
@@ -1896,7 +1759,6 @@ declare class FixedClusterPool<Data = unknown, Response = unknown> extends Abstr
|
|
|
1896
1759
|
declare class DynamicClusterPool<Data = unknown, Response = unknown> extends FixedClusterPool<Data, Response> {
|
|
1897
1760
|
/**
|
|
1898
1761
|
* Constructs a new poolifier dynamic cluster pool.
|
|
1899
|
-
*
|
|
1900
1762
|
* @param min - Minimum number of workers which are always active.
|
|
1901
1763
|
* @param max - Maximum number of workers that can be created by this pool.
|
|
1902
1764
|
* @param filePath - Path to an implementation of a `ClusterWorker` file, which can be relative or absolute.
|
|
@@ -1919,7 +1781,6 @@ declare class DynamicClusterPool<Data = unknown, Response = unknown> extends Fix
|
|
|
1919
1781
|
type ThreadPoolOptions = PoolOptions<Worker$1>;
|
|
1920
1782
|
/**
|
|
1921
1783
|
* A thread pool with a fixed number of threads.
|
|
1922
|
-
*
|
|
1923
1784
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1924
1785
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
1925
1786
|
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
|
|
@@ -1928,10 +1789,10 @@ type ThreadPoolOptions = PoolOptions<Worker$1>;
|
|
|
1928
1789
|
declare class FixedThreadPool<Data = unknown, Response = unknown> extends AbstractPool<Worker$1, Data, Response> {
|
|
1929
1790
|
/**
|
|
1930
1791
|
* Constructs a new poolifier fixed thread pool.
|
|
1931
|
-
*
|
|
1932
1792
|
* @param numberOfThreads - Number of threads for this pool.
|
|
1933
1793
|
* @param filePath - Path to an implementation of a `ThreadWorker` file, which can be relative or absolute.
|
|
1934
1794
|
* @param opts - Options for this fixed thread pool.
|
|
1795
|
+
* @param maximumNumberOfThreads - The maximum number of threads for this pool.
|
|
1935
1796
|
*/
|
|
1936
1797
|
constructor(numberOfThreads: number, filePath: string, opts?: ThreadPoolOptions, maximumNumberOfThreads?: number);
|
|
1937
1798
|
/** @inheritDoc */
|
|
@@ -1963,7 +1824,6 @@ declare class FixedThreadPool<Data = unknown, Response = unknown> extends Abstra
|
|
|
1963
1824
|
*
|
|
1964
1825
|
* This thread pool creates new threads when the others are busy, up to the maximum number of threads.
|
|
1965
1826
|
* When the maximum number of threads is reached and workers are busy, an event is emitted. If you want to listen to this event, use the pool's `emitter`.
|
|
1966
|
-
*
|
|
1967
1827
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1968
1828
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
1969
1829
|
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
|
|
@@ -1972,7 +1832,6 @@ declare class FixedThreadPool<Data = unknown, Response = unknown> extends Abstra
|
|
|
1972
1832
|
declare class DynamicThreadPool<Data = unknown, Response = unknown> extends FixedThreadPool<Data, Response> {
|
|
1973
1833
|
/**
|
|
1974
1834
|
* Constructs a new poolifier dynamic thread pool.
|
|
1975
|
-
*
|
|
1976
1835
|
* @param min - Minimum number of threads which are always active.
|
|
1977
1836
|
* @param max - Maximum number of threads that can be created by this pool.
|
|
1978
1837
|
* @param filePath - Path to an implementation of a `ThreadWorker` file, which can be relative or absolute.
|
|
@@ -1991,7 +1850,6 @@ declare class DynamicThreadPool<Data = unknown, Response = unknown> extends Fixe
|
|
|
1991
1850
|
|
|
1992
1851
|
/**
|
|
1993
1852
|
* Priority queue node.
|
|
1994
|
-
*
|
|
1995
1853
|
* @typeParam T - Type of priority queue node data.
|
|
1996
1854
|
* @internal
|
|
1997
1855
|
*/
|
|
@@ -2000,7 +1858,6 @@ interface PriorityQueueNode<T> extends FixedPriorityQueue<T> {
|
|
|
2000
1858
|
}
|
|
2001
1859
|
/**
|
|
2002
1860
|
* Priority queue.
|
|
2003
|
-
*
|
|
2004
1861
|
* @typeParam T - Type of priority queue data.
|
|
2005
1862
|
* @internal
|
|
2006
1863
|
*/
|
|
@@ -2012,7 +1869,6 @@ declare class PriorityQueue<T> {
|
|
|
2012
1869
|
maxSize: number;
|
|
2013
1870
|
/**
|
|
2014
1871
|
* Constructs a priority queue.
|
|
2015
|
-
*
|
|
2016
1872
|
* @param bucketSize - Prioritized bucket size. @defaultValue defaultBucketSize
|
|
2017
1873
|
* @param enablePriority - Whether to enable priority. @defaultValue false
|
|
2018
1874
|
* @returns PriorityQueue.
|
|
@@ -2030,7 +1886,6 @@ declare class PriorityQueue<T> {
|
|
|
2030
1886
|
get buckets(): number;
|
|
2031
1887
|
/**
|
|
2032
1888
|
* Enqueue data into the priority queue.
|
|
2033
|
-
*
|
|
2034
1889
|
* @param data - Data to enqueue.
|
|
2035
1890
|
* @param priority - Priority of the data. Lower values have higher priority.
|
|
2036
1891
|
* @returns The new size of the priority queue.
|
|
@@ -2038,7 +1893,6 @@ declare class PriorityQueue<T> {
|
|
|
2038
1893
|
enqueue(data: T, priority?: number): number;
|
|
2039
1894
|
/**
|
|
2040
1895
|
* Dequeue data from the priority queue.
|
|
2041
|
-
*
|
|
2042
1896
|
* @param bucket - The prioritized bucket to dequeue from.
|
|
2043
1897
|
* @returns The dequeued data or `undefined` if the priority queue is empty.
|
|
2044
1898
|
*/
|
|
@@ -2049,7 +1903,6 @@ declare class PriorityQueue<T> {
|
|
|
2049
1903
|
clear(): void;
|
|
2050
1904
|
/**
|
|
2051
1905
|
* Returns an iterator for the priority queue.
|
|
2052
|
-
*
|
|
2053
1906
|
* @returns An iterator for the priority queue.
|
|
2054
1907
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
|
|
2055
1908
|
*/
|
|
@@ -2059,14 +1912,12 @@ declare class PriorityQueue<T> {
|
|
|
2059
1912
|
/**
|
|
2060
1913
|
* Returns safe host OS optimized estimate of the default amount of parallelism a pool should use.
|
|
2061
1914
|
* Always returns a value greater than zero.
|
|
2062
|
-
*
|
|
2063
1915
|
* @returns The host OS optimized maximum pool size.
|
|
2064
1916
|
*/
|
|
2065
1917
|
declare const availableParallelism: () => number;
|
|
2066
1918
|
|
|
2067
1919
|
/**
|
|
2068
1920
|
* Base class that implements some shared logic for all poolifier workers.
|
|
2069
|
-
*
|
|
2070
1921
|
* @typeParam MainWorker - Type of main worker.
|
|
2071
1922
|
* @typeParam Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
|
|
2072
1923
|
* @typeParam Response - Type of response the worker sends back to the main worker. This can only be structured-cloneable data.
|
|
@@ -2097,7 +1948,6 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
2097
1948
|
protected activeInterval?: NodeJS.Timeout;
|
|
2098
1949
|
/**
|
|
2099
1950
|
* Constructs a new poolifier worker.
|
|
2100
|
-
*
|
|
2101
1951
|
* @param isMain - Whether this is the main worker or not.
|
|
2102
1952
|
* @param mainWorker - Reference to main worker.
|
|
2103
1953
|
* @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked. The first function is the default function.
|
|
@@ -2107,13 +1957,11 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
2107
1957
|
private checkWorkerOptions;
|
|
2108
1958
|
/**
|
|
2109
1959
|
* Checks if the `taskFunctions` parameter is passed to the constructor and valid.
|
|
2110
|
-
*
|
|
2111
1960
|
* @param taskFunctions - The task function(s) parameter that should be checked.
|
|
2112
1961
|
*/
|
|
2113
1962
|
private checkTaskFunctions;
|
|
2114
1963
|
/**
|
|
2115
1964
|
* Checks if the worker has a task function with the given name.
|
|
2116
|
-
*
|
|
2117
1965
|
* @param name - The name of the task function to check.
|
|
2118
1966
|
* @returns Whether the worker has a task function with the given name or not.
|
|
2119
1967
|
*/
|
|
@@ -2121,7 +1969,6 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
2121
1969
|
/**
|
|
2122
1970
|
* Adds a task function to the worker.
|
|
2123
1971
|
* If a task function with the same name already exists, it is replaced.
|
|
2124
|
-
*
|
|
2125
1972
|
* @param name - The name of the task function to add.
|
|
2126
1973
|
* @param fn - The task function to add.
|
|
2127
1974
|
* @returns Whether the task function was added or not.
|
|
@@ -2129,46 +1976,39 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
2129
1976
|
addTaskFunction(name: string, fn: TaskFunction<Data, Response> | TaskFunctionObject<Data, Response>): TaskFunctionOperationResult;
|
|
2130
1977
|
/**
|
|
2131
1978
|
* Removes a task function from the worker.
|
|
2132
|
-
*
|
|
2133
1979
|
* @param name - The name of the task function to remove.
|
|
2134
1980
|
* @returns Whether the task function existed and was removed or not.
|
|
2135
1981
|
*/
|
|
2136
1982
|
removeTaskFunction(name: string): TaskFunctionOperationResult;
|
|
2137
1983
|
/**
|
|
2138
1984
|
* Lists the properties of the worker's task functions.
|
|
2139
|
-
*
|
|
2140
1985
|
* @returns The properties of the worker's task functions.
|
|
2141
1986
|
*/
|
|
2142
1987
|
listTaskFunctionsProperties(): TaskFunctionProperties[];
|
|
2143
1988
|
/**
|
|
2144
1989
|
* Sets the default task function to use in the worker.
|
|
2145
|
-
*
|
|
2146
1990
|
* @param name - The name of the task function to use as default task function.
|
|
2147
1991
|
* @returns Whether the default task function was set or not.
|
|
2148
1992
|
*/
|
|
2149
1993
|
setDefaultTaskFunction(name: string): TaskFunctionOperationResult;
|
|
2150
1994
|
/**
|
|
2151
1995
|
* Handles the ready message sent by the main worker.
|
|
2152
|
-
*
|
|
2153
1996
|
* @param message - The ready message.
|
|
2154
1997
|
*/
|
|
2155
1998
|
protected abstract handleReadyMessage(message: MessageValue<Data>): void;
|
|
2156
1999
|
/**
|
|
2157
2000
|
* Worker message listener.
|
|
2158
|
-
*
|
|
2159
2001
|
* @param message - The received message.
|
|
2160
2002
|
*/
|
|
2161
2003
|
protected messageListener(message: MessageValue<Data>): void;
|
|
2162
2004
|
protected handleTaskFunctionOperationMessage(message: MessageValue<Data>): void;
|
|
2163
2005
|
/**
|
|
2164
2006
|
* Handles a kill message sent by the main worker.
|
|
2165
|
-
*
|
|
2166
2007
|
* @param message - The kill message.
|
|
2167
2008
|
*/
|
|
2168
|
-
protected handleKillMessage(
|
|
2009
|
+
protected handleKillMessage(message: MessageValue<Data>): void;
|
|
2169
2010
|
/**
|
|
2170
2011
|
* Check if the message worker id is set and matches the worker id.
|
|
2171
|
-
*
|
|
2172
2012
|
* @param message - The message to check.
|
|
2173
2013
|
* @throws {@link https://nodejs.org/api/errors.html#class-error} If the message worker id is not set or does not match the worker id.
|
|
2174
2014
|
*/
|
|
@@ -2187,14 +2027,12 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
2187
2027
|
private checkActive;
|
|
2188
2028
|
/**
|
|
2189
2029
|
* Returns the main worker.
|
|
2190
|
-
*
|
|
2191
2030
|
* @returns Reference to the main worker.
|
|
2192
2031
|
* @throws {@link https://nodejs.org/api/errors.html#class-error} If the main worker is not set.
|
|
2193
2032
|
*/
|
|
2194
2033
|
protected getMainWorker(): MainWorker;
|
|
2195
2034
|
/**
|
|
2196
2035
|
* Sends a message to main worker.
|
|
2197
|
-
*
|
|
2198
2036
|
* @param message - The response message.
|
|
2199
2037
|
*/
|
|
2200
2038
|
protected abstract sendToMainWorker(message: MessageValue<Response, Data>): void;
|
|
@@ -2204,27 +2042,23 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
2204
2042
|
protected sendTaskFunctionsPropertiesToMainWorker(): void;
|
|
2205
2043
|
/**
|
|
2206
2044
|
* Handles an error and convert it to a string so it can be sent back to the main worker.
|
|
2207
|
-
*
|
|
2208
2045
|
* @param error - The error raised by the worker.
|
|
2209
2046
|
* @returns The error message.
|
|
2210
2047
|
*/
|
|
2211
2048
|
protected handleError(error: Error | string): string;
|
|
2212
2049
|
/**
|
|
2213
2050
|
* Runs the given task.
|
|
2214
|
-
*
|
|
2215
2051
|
* @param task - The task to execute.
|
|
2216
2052
|
*/
|
|
2217
2053
|
protected readonly run: (task: Task<Data>) => void;
|
|
2218
2054
|
/**
|
|
2219
2055
|
* Runs the given task function synchronously.
|
|
2220
|
-
*
|
|
2221
2056
|
* @param fn - Task function that will be executed.
|
|
2222
2057
|
* @param task - Input data for the task function.
|
|
2223
2058
|
*/
|
|
2224
2059
|
protected readonly runSync: (fn: TaskSyncFunction<Data, Response>, task: Task<Data>) => void;
|
|
2225
2060
|
/**
|
|
2226
2061
|
* Runs the given task function asynchronously.
|
|
2227
|
-
*
|
|
2228
2062
|
* @param fn - Task function that will be executed.
|
|
2229
2063
|
* @param task - Input data for the task function.
|
|
2230
2064
|
*/
|
|
@@ -2242,7 +2076,6 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
2242
2076
|
*
|
|
2243
2077
|
* If you use a `DynamicClusterPool` the extra workers that were created will be terminated,
|
|
2244
2078
|
* but the minimum number of workers will be guaranteed.
|
|
2245
|
-
*
|
|
2246
2079
|
* @typeParam Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
|
|
2247
2080
|
* @typeParam Response - Type of response the worker sends back to the main worker. This can only be structured-cloneable data.
|
|
2248
2081
|
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
|
|
@@ -2251,7 +2084,6 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
2251
2084
|
declare class ClusterWorker<Data = unknown, Response = unknown> extends AbstractWorker<Worker, Data, Response> {
|
|
2252
2085
|
/**
|
|
2253
2086
|
* Constructs a new poolifier cluster worker.
|
|
2254
|
-
*
|
|
2255
2087
|
* @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked.
|
|
2256
2088
|
* @param opts - Options for the worker.
|
|
2257
2089
|
*/
|
|
@@ -2272,7 +2104,6 @@ declare class ClusterWorker<Data = unknown, Response = unknown> extends Abstract
|
|
|
2272
2104
|
*
|
|
2273
2105
|
* If you use a `DynamicThreadPool` the extra workers that were created will be terminated,
|
|
2274
2106
|
* but the minimum number of workers will be guaranteed.
|
|
2275
|
-
*
|
|
2276
2107
|
* @typeParam Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
|
|
2277
2108
|
* @typeParam Response - Type of response the worker sends back to the main thread. This can only be structured-cloneable data.
|
|
2278
2109
|
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
|
|
@@ -2285,7 +2116,6 @@ declare class ThreadWorker<Data = unknown, Response = unknown> extends AbstractW
|
|
|
2285
2116
|
private port?;
|
|
2286
2117
|
/**
|
|
2287
2118
|
* Constructs a new poolifier thread worker.
|
|
2288
|
-
*
|
|
2289
2119
|
* @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked.
|
|
2290
2120
|
* @param opts - Options for the worker.
|
|
2291
2121
|
*/
|
|
@@ -2300,7 +2130,6 @@ declare class ThreadWorker<Data = unknown, Response = unknown> extends AbstractW
|
|
|
2300
2130
|
protected readonly sendToMainWorker: (message: MessageValue<Response>) => void;
|
|
2301
2131
|
/**
|
|
2302
2132
|
* @inheritDoc
|
|
2303
|
-
* @override
|
|
2304
2133
|
*/
|
|
2305
2134
|
protected handleError(error: Error | string): string;
|
|
2306
2135
|
}
|