poolifier 4.0.13 → 4.0.15

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.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
- * 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.
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: Array<IWorkerNode<Worker, Data>>;
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: Array<IWorkerNode<Worker, Data>>;
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.
@@ -1523,16 +1416,17 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
1523
1416
  /** @inheritDoc */
1524
1417
  get info(): PoolInfo;
1525
1418
  /**
1526
- * The pool readiness boolean status.
1419
+ * Whether the pool is ready or not.
1420
+ * @returns The pool readiness boolean status.
1527
1421
  */
1528
1422
  private get ready();
1529
1423
  /**
1530
- * The pool emptiness boolean status.
1424
+ * Whether the pool is empty or not.
1425
+ * @returns The pool emptiness boolean status.
1531
1426
  */
1532
1427
  protected get empty(): boolean;
1533
1428
  /**
1534
1429
  * The approximate pool utilization.
1535
- *
1536
1430
  * @returns The pool utilization.
1537
1431
  */
1538
1432
  private get utilization();
@@ -1548,14 +1442,12 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
1548
1442
  protected abstract get worker(): WorkerType;
1549
1443
  /**
1550
1444
  * Checks if the worker id sent in the received message from a worker is valid.
1551
- *
1552
1445
  * @param message - The received message.
1553
1446
  * @throws {@link https://nodejs.org/api/errors.html#class-error} If the worker id is invalid.
1554
1447
  */
1555
1448
  private checkMessageWorkerId;
1556
1449
  /**
1557
1450
  * Gets the worker node key given its worker id.
1558
- *
1559
1451
  * @param workerId - The worker id.
1560
1452
  * @returns The worker node key if the worker id is found in the pool worker nodes, `-1` otherwise.
1561
1453
  */
@@ -1576,19 +1468,16 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
1576
1468
  private unsetTasksStealingOnBackPressure;
1577
1469
  /**
1578
1470
  * Whether the pool is full or not.
1579
- *
1580
- * The pool filling boolean status.
1471
+ * @returns The pool fullness boolean status.
1581
1472
  */
1582
1473
  protected get full(): boolean;
1583
1474
  /**
1584
1475
  * Whether the pool is busy or not.
1585
- *
1586
- * The pool busyness boolean status.
1476
+ * @returns The pool busyness boolean status.
1587
1477
  */
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.
@@ -2020,17 +1876,18 @@ declare class PriorityQueue<T> {
2020
1876
  constructor(bucketSize?: number, enablePriority?: boolean);
2021
1877
  /**
2022
1878
  * The priority queue size.
1879
+ * @returns The priority queue size.
2023
1880
  */
2024
1881
  get size(): number;
2025
1882
  get enablePriority(): boolean;
2026
1883
  set enablePriority(enablePriority: boolean);
2027
1884
  /**
2028
1885
  * The number of filled prioritized buckets.
1886
+ * @returns The number of filled prioritized buckets.
2029
1887
  */
2030
1888
  get buckets(): number;
2031
1889
  /**
2032
1890
  * Enqueue data into the priority queue.
2033
- *
2034
1891
  * @param data - Data to enqueue.
2035
1892
  * @param priority - Priority of the data. Lower values have higher priority.
2036
1893
  * @returns The new size of the priority queue.
@@ -2038,7 +1895,6 @@ declare class PriorityQueue<T> {
2038
1895
  enqueue(data: T, priority?: number): number;
2039
1896
  /**
2040
1897
  * Dequeue data from the priority queue.
2041
- *
2042
1898
  * @param bucket - The prioritized bucket to dequeue from.
2043
1899
  * @returns The dequeued data or `undefined` if the priority queue is empty.
2044
1900
  */
@@ -2049,7 +1905,6 @@ declare class PriorityQueue<T> {
2049
1905
  clear(): void;
2050
1906
  /**
2051
1907
  * Returns an iterator for the priority queue.
2052
- *
2053
1908
  * @returns An iterator for the priority queue.
2054
1909
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
2055
1910
  */
@@ -2059,14 +1914,12 @@ declare class PriorityQueue<T> {
2059
1914
  /**
2060
1915
  * Returns safe host OS optimized estimate of the default amount of parallelism a pool should use.
2061
1916
  * Always returns a value greater than zero.
2062
- *
2063
1917
  * @returns The host OS optimized maximum pool size.
2064
1918
  */
2065
1919
  declare const availableParallelism: () => number;
2066
1920
 
2067
1921
  /**
2068
1922
  * Base class that implements some shared logic for all poolifier workers.
2069
- *
2070
1923
  * @typeParam MainWorker - Type of main worker.
2071
1924
  * @typeParam Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
2072
1925
  * @typeParam Response - Type of response the worker sends back to the main worker. This can only be structured-cloneable data.
@@ -2097,7 +1950,6 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
2097
1950
  protected activeInterval?: NodeJS.Timeout;
2098
1951
  /**
2099
1952
  * Constructs a new poolifier worker.
2100
- *
2101
1953
  * @param isMain - Whether this is the main worker or not.
2102
1954
  * @param mainWorker - Reference to main worker.
2103
1955
  * @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 +1959,11 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
2107
1959
  private checkWorkerOptions;
2108
1960
  /**
2109
1961
  * Checks if the `taskFunctions` parameter is passed to the constructor and valid.
2110
- *
2111
1962
  * @param taskFunctions - The task function(s) parameter that should be checked.
2112
1963
  */
2113
1964
  private checkTaskFunctions;
2114
1965
  /**
2115
1966
  * Checks if the worker has a task function with the given name.
2116
- *
2117
1967
  * @param name - The name of the task function to check.
2118
1968
  * @returns Whether the worker has a task function with the given name or not.
2119
1969
  */
@@ -2121,7 +1971,6 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
2121
1971
  /**
2122
1972
  * Adds a task function to the worker.
2123
1973
  * If a task function with the same name already exists, it is replaced.
2124
- *
2125
1974
  * @param name - The name of the task function to add.
2126
1975
  * @param fn - The task function to add.
2127
1976
  * @returns Whether the task function was added or not.
@@ -2129,46 +1978,39 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
2129
1978
  addTaskFunction(name: string, fn: TaskFunction<Data, Response> | TaskFunctionObject<Data, Response>): TaskFunctionOperationResult;
2130
1979
  /**
2131
1980
  * Removes a task function from the worker.
2132
- *
2133
1981
  * @param name - The name of the task function to remove.
2134
1982
  * @returns Whether the task function existed and was removed or not.
2135
1983
  */
2136
1984
  removeTaskFunction(name: string): TaskFunctionOperationResult;
2137
1985
  /**
2138
1986
  * Lists the properties of the worker's task functions.
2139
- *
2140
1987
  * @returns The properties of the worker's task functions.
2141
1988
  */
2142
1989
  listTaskFunctionsProperties(): TaskFunctionProperties[];
2143
1990
  /**
2144
1991
  * Sets the default task function to use in the worker.
2145
- *
2146
1992
  * @param name - The name of the task function to use as default task function.
2147
1993
  * @returns Whether the default task function was set or not.
2148
1994
  */
2149
1995
  setDefaultTaskFunction(name: string): TaskFunctionOperationResult;
2150
1996
  /**
2151
1997
  * Handles the ready message sent by the main worker.
2152
- *
2153
1998
  * @param message - The ready message.
2154
1999
  */
2155
2000
  protected abstract handleReadyMessage(message: MessageValue<Data>): void;
2156
2001
  /**
2157
2002
  * Worker message listener.
2158
- *
2159
2003
  * @param message - The received message.
2160
2004
  */
2161
2005
  protected messageListener(message: MessageValue<Data>): void;
2162
2006
  protected handleTaskFunctionOperationMessage(message: MessageValue<Data>): void;
2163
2007
  /**
2164
2008
  * Handles a kill message sent by the main worker.
2165
- *
2166
2009
  * @param message - The kill message.
2167
2010
  */
2168
- protected handleKillMessage(_message: MessageValue<Data>): void;
2011
+ protected handleKillMessage(message: MessageValue<Data>): void;
2169
2012
  /**
2170
2013
  * Check if the message worker id is set and matches the worker id.
2171
- *
2172
2014
  * @param message - The message to check.
2173
2015
  * @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
2016
  */
@@ -2187,14 +2029,12 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
2187
2029
  private checkActive;
2188
2030
  /**
2189
2031
  * Returns the main worker.
2190
- *
2191
2032
  * @returns Reference to the main worker.
2192
2033
  * @throws {@link https://nodejs.org/api/errors.html#class-error} If the main worker is not set.
2193
2034
  */
2194
2035
  protected getMainWorker(): MainWorker;
2195
2036
  /**
2196
2037
  * Sends a message to main worker.
2197
- *
2198
2038
  * @param message - The response message.
2199
2039
  */
2200
2040
  protected abstract sendToMainWorker(message: MessageValue<Response, Data>): void;
@@ -2204,27 +2044,23 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
2204
2044
  protected sendTaskFunctionsPropertiesToMainWorker(): void;
2205
2045
  /**
2206
2046
  * Handles an error and convert it to a string so it can be sent back to the main worker.
2207
- *
2208
2047
  * @param error - The error raised by the worker.
2209
2048
  * @returns The error message.
2210
2049
  */
2211
2050
  protected handleError(error: Error | string): string;
2212
2051
  /**
2213
2052
  * Runs the given task.
2214
- *
2215
2053
  * @param task - The task to execute.
2216
2054
  */
2217
2055
  protected readonly run: (task: Task<Data>) => void;
2218
2056
  /**
2219
2057
  * Runs the given task function synchronously.
2220
- *
2221
2058
  * @param fn - Task function that will be executed.
2222
2059
  * @param task - Input data for the task function.
2223
2060
  */
2224
2061
  protected readonly runSync: (fn: TaskSyncFunction<Data, Response>, task: Task<Data>) => void;
2225
2062
  /**
2226
2063
  * Runs the given task function asynchronously.
2227
- *
2228
2064
  * @param fn - Task function that will be executed.
2229
2065
  * @param task - Input data for the task function.
2230
2066
  */
@@ -2242,7 +2078,6 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
2242
2078
  *
2243
2079
  * If you use a `DynamicClusterPool` the extra workers that were created will be terminated,
2244
2080
  * but the minimum number of workers will be guaranteed.
2245
- *
2246
2081
  * @typeParam Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
2247
2082
  * @typeParam Response - Type of response the worker sends back to the main worker. This can only be structured-cloneable data.
2248
2083
  * @author [Christopher Quadflieg](https://github.com/Shinigami92)
@@ -2251,7 +2086,6 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
2251
2086
  declare class ClusterWorker<Data = unknown, Response = unknown> extends AbstractWorker<Worker, Data, Response> {
2252
2087
  /**
2253
2088
  * Constructs a new poolifier cluster worker.
2254
- *
2255
2089
  * @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked.
2256
2090
  * @param opts - Options for the worker.
2257
2091
  */
@@ -2272,7 +2106,6 @@ declare class ClusterWorker<Data = unknown, Response = unknown> extends Abstract
2272
2106
  *
2273
2107
  * If you use a `DynamicThreadPool` the extra workers that were created will be terminated,
2274
2108
  * but the minimum number of workers will be guaranteed.
2275
- *
2276
2109
  * @typeParam Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
2277
2110
  * @typeParam Response - Type of response the worker sends back to the main thread. This can only be structured-cloneable data.
2278
2111
  * @author [Alessandro Pio Ardizio](https://github.com/pioardi)
@@ -2285,7 +2118,6 @@ declare class ThreadWorker<Data = unknown, Response = unknown> extends AbstractW
2285
2118
  private port?;
2286
2119
  /**
2287
2120
  * Constructs a new poolifier thread worker.
2288
- *
2289
2121
  * @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked.
2290
2122
  * @param opts - Options for the worker.
2291
2123
  */
@@ -2300,7 +2132,6 @@ declare class ThreadWorker<Data = unknown, Response = unknown> extends AbstractW
2300
2132
  protected readonly sendToMainWorker: (message: MessageValue<Response>) => void;
2301
2133
  /**
2302
2134
  * @inheritDoc
2303
- * @override
2304
2135
  */
2305
2136
  protected handleError(error: Error | string): string;
2306
2137
  }