poolifier 3.1.30 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +381 -302
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/package.json +10 -10
package/lib/index.d.ts
CHANGED
|
@@ -29,86 +29,177 @@ declare class CircularArray<T> extends Array<T> {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* @typeParam T - Type of linked list node data.
|
|
35
|
-
* @internal
|
|
32
|
+
* Enumeration of worker choice strategies.
|
|
36
33
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
declare const WorkerChoiceStrategies: Readonly<{
|
|
35
|
+
ROUND_ROBIN: 'ROUND_ROBIN';
|
|
36
|
+
LEAST_USED: 'LEAST_USED';
|
|
37
|
+
LEAST_BUSY: 'LEAST_BUSY';
|
|
38
|
+
LEAST_ELU: 'LEAST_ELU';
|
|
39
|
+
FAIR_SHARE: 'FAIR_SHARE';
|
|
40
|
+
WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN';
|
|
41
|
+
INTERLEAVED_WEIGHTED_ROUND_ROBIN: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN';
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Worker choice strategy.
|
|
45
|
+
*/
|
|
46
|
+
type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies;
|
|
47
|
+
/**
|
|
48
|
+
* Enumeration of measurements.
|
|
49
|
+
*/
|
|
50
|
+
declare const Measurements: Readonly<{
|
|
51
|
+
runTime: 'runTime';
|
|
52
|
+
waitTime: 'waitTime';
|
|
53
|
+
elu: 'elu';
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Measurement.
|
|
57
|
+
*/
|
|
58
|
+
type Measurement = keyof typeof Measurements;
|
|
59
|
+
/**
|
|
60
|
+
* Measurement options.
|
|
61
|
+
*/
|
|
62
|
+
interface MeasurementOptions {
|
|
63
|
+
/**
|
|
64
|
+
* Set measurement median.
|
|
65
|
+
*/
|
|
66
|
+
readonly median: boolean;
|
|
41
67
|
}
|
|
42
68
|
/**
|
|
43
|
-
*
|
|
44
|
-
* Implemented with a doubly linked list.
|
|
45
|
-
*
|
|
46
|
-
* @typeParam T - Type of deque data.
|
|
47
|
-
* @internal
|
|
69
|
+
* Worker choice strategy options.
|
|
48
70
|
*/
|
|
49
|
-
|
|
50
|
-
private head?;
|
|
51
|
-
private tail?;
|
|
52
|
-
/** The size of the deque. */
|
|
53
|
-
size: number;
|
|
54
|
-
/** The maximum size of the deque. */
|
|
55
|
-
maxSize: number;
|
|
56
|
-
constructor();
|
|
71
|
+
interface WorkerChoiceStrategyOptions {
|
|
57
72
|
/**
|
|
58
|
-
*
|
|
73
|
+
* Measurement to use in worker choice strategy supporting it.
|
|
74
|
+
*/
|
|
75
|
+
readonly measurement?: Measurement;
|
|
76
|
+
/**
|
|
77
|
+
* Runtime options.
|
|
59
78
|
*
|
|
60
|
-
* @
|
|
61
|
-
* @returns The new size of the deque.
|
|
79
|
+
* @defaultValue \{ median: false \}
|
|
62
80
|
*/
|
|
63
|
-
|
|
81
|
+
readonly runTime?: MeasurementOptions;
|
|
64
82
|
/**
|
|
65
|
-
*
|
|
83
|
+
* Wait time options.
|
|
66
84
|
*
|
|
67
|
-
* @
|
|
68
|
-
* @returns The new size of the deque.
|
|
85
|
+
* @defaultValue \{ median: false \}
|
|
69
86
|
*/
|
|
70
|
-
|
|
87
|
+
readonly waitTime?: MeasurementOptions;
|
|
71
88
|
/**
|
|
72
|
-
*
|
|
89
|
+
* Event loop utilization options.
|
|
73
90
|
*
|
|
74
|
-
* @
|
|
91
|
+
* @defaultValue \{ median: false \}
|
|
75
92
|
*/
|
|
76
|
-
|
|
93
|
+
readonly elu?: MeasurementOptions;
|
|
77
94
|
/**
|
|
78
|
-
*
|
|
95
|
+
* Worker weights to use for weighted round robin worker selection strategies.
|
|
96
|
+
* A weight is tasks maximum execution time in milliseconds for a worker node.
|
|
79
97
|
*
|
|
80
|
-
* @
|
|
98
|
+
* @defaultValue Weights computed automatically given the CPU performance.
|
|
81
99
|
*/
|
|
82
|
-
|
|
100
|
+
weights?: Record<number, number>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Measurement statistics requirements.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
interface MeasurementStatisticsRequirements {
|
|
83
108
|
/**
|
|
84
|
-
*
|
|
85
|
-
* @returns The first data or `undefined` if the deque is empty.
|
|
109
|
+
* Requires measurement aggregate.
|
|
86
110
|
*/
|
|
87
|
-
|
|
111
|
+
aggregate: boolean;
|
|
88
112
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @returns The last data or `undefined` if the deque is empty.
|
|
113
|
+
* Requires measurement average.
|
|
91
114
|
*/
|
|
92
|
-
|
|
115
|
+
average: boolean;
|
|
93
116
|
/**
|
|
94
|
-
*
|
|
117
|
+
* Requires measurement median.
|
|
95
118
|
*/
|
|
96
|
-
|
|
119
|
+
median: boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Pool worker node worker usage statistics requirements.
|
|
123
|
+
*
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
interface TaskStatisticsRequirements {
|
|
127
|
+
/**
|
|
128
|
+
* Tasks runtime requirements.
|
|
129
|
+
*/
|
|
130
|
+
readonly runTime: MeasurementStatisticsRequirements;
|
|
131
|
+
/**
|
|
132
|
+
* Tasks wait time requirements.
|
|
133
|
+
*/
|
|
134
|
+
readonly waitTime: MeasurementStatisticsRequirements;
|
|
97
135
|
/**
|
|
98
|
-
*
|
|
136
|
+
* Tasks event loop utilization requirements.
|
|
137
|
+
*/
|
|
138
|
+
readonly elu: MeasurementStatisticsRequirements;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Strategy policy.
|
|
142
|
+
*
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
interface StrategyPolicy {
|
|
146
|
+
/**
|
|
147
|
+
* Expects tasks execution on the newly created dynamic worker.
|
|
148
|
+
*/
|
|
149
|
+
readonly dynamicWorkerUsage: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Expects the newly created dynamic worker to be flagged as ready.
|
|
152
|
+
*/
|
|
153
|
+
readonly dynamicWorkerReady: boolean;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Worker choice strategy interface.
|
|
157
|
+
*
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
interface IWorkerChoiceStrategy {
|
|
161
|
+
/**
|
|
162
|
+
* Strategy policy.
|
|
163
|
+
*/
|
|
164
|
+
readonly strategyPolicy: StrategyPolicy;
|
|
165
|
+
/**
|
|
166
|
+
* Tasks statistics requirements.
|
|
167
|
+
*/
|
|
168
|
+
readonly taskStatisticsRequirements: TaskStatisticsRequirements;
|
|
169
|
+
/**
|
|
170
|
+
* Resets strategy internals.
|
|
99
171
|
*
|
|
100
|
-
* @returns
|
|
101
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
|
|
172
|
+
* @returns `true` if the reset is successful, `false` otherwise.
|
|
102
173
|
*/
|
|
103
|
-
|
|
174
|
+
readonly reset: () => boolean;
|
|
104
175
|
/**
|
|
105
|
-
*
|
|
176
|
+
* Updates the worker node key strategy internals.
|
|
177
|
+
* This is called after a task has been executed on a worker node.
|
|
106
178
|
*
|
|
107
|
-
* @returns
|
|
108
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
|
|
179
|
+
* @returns `true` if the update is successful, `false` otherwise.
|
|
109
180
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
181
|
+
readonly update: (workerNodeKey: number) => boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Chooses a worker node in the pool and returns its key.
|
|
184
|
+
* If no worker nodes are not eligible, `undefined` is returned.
|
|
185
|
+
* If `undefined` is returned, the caller retry.
|
|
186
|
+
*
|
|
187
|
+
* @returns The worker node key or `undefined`.
|
|
188
|
+
*/
|
|
189
|
+
readonly choose: () => number | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Removes the worker node key from strategy internals.
|
|
192
|
+
*
|
|
193
|
+
* @param workerNodeKey - The worker node key.
|
|
194
|
+
* @returns `true` if the worker node key is removed, `false` otherwise.
|
|
195
|
+
*/
|
|
196
|
+
readonly remove: (workerNodeKey: number) => boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Sets the worker choice strategy options.
|
|
199
|
+
*
|
|
200
|
+
* @param opts - The worker choice strategy options.
|
|
201
|
+
*/
|
|
202
|
+
readonly setOptions: (opts: WorkerChoiceStrategyOptions | undefined) => void;
|
|
112
203
|
}
|
|
113
204
|
|
|
114
205
|
/**
|
|
@@ -219,6 +310,23 @@ interface WorkerStatistics {
|
|
|
219
310
|
*/
|
|
220
311
|
readonly elu: boolean;
|
|
221
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Task function properties.
|
|
315
|
+
*/
|
|
316
|
+
interface TaskFunctionProperties {
|
|
317
|
+
/**
|
|
318
|
+
* Task function name.
|
|
319
|
+
*/
|
|
320
|
+
readonly name: string;
|
|
321
|
+
/**
|
|
322
|
+
* Task function priority. Lower values have higher priority.
|
|
323
|
+
*/
|
|
324
|
+
readonly priority?: number;
|
|
325
|
+
/**
|
|
326
|
+
* Task function worker choice strategy.
|
|
327
|
+
*/
|
|
328
|
+
readonly strategy?: WorkerChoiceStrategy;
|
|
329
|
+
}
|
|
222
330
|
/**
|
|
223
331
|
* Message object that is passed as a task between main worker and worker.
|
|
224
332
|
*
|
|
@@ -234,6 +342,16 @@ interface Task<Data = unknown> {
|
|
|
234
342
|
* Task input data that will be passed to the worker.
|
|
235
343
|
*/
|
|
236
344
|
readonly data?: Data;
|
|
345
|
+
/**
|
|
346
|
+
* Task priority. Lower values have higher priority.
|
|
347
|
+
*
|
|
348
|
+
* @defaultValue 0
|
|
349
|
+
*/
|
|
350
|
+
readonly priority?: number;
|
|
351
|
+
/**
|
|
352
|
+
* Task worker choice strategy.
|
|
353
|
+
*/
|
|
354
|
+
readonly strategy?: WorkerChoiceStrategy;
|
|
237
355
|
/**
|
|
238
356
|
* Array of transferable objects.
|
|
239
357
|
*/
|
|
@@ -245,7 +363,7 @@ interface Task<Data = unknown> {
|
|
|
245
363
|
/**
|
|
246
364
|
* Task UUID.
|
|
247
365
|
*/
|
|
248
|
-
readonly taskId?: string
|
|
366
|
+
readonly taskId?: `${string}-${string}-${string}-${string}-${string}`;
|
|
249
367
|
}
|
|
250
368
|
/**
|
|
251
369
|
* Message object that is passed between main worker and worker.
|
|
@@ -283,17 +401,17 @@ interface MessageValue<Data = unknown, ErrorData = unknown> extends Task<Data> {
|
|
|
283
401
|
*/
|
|
284
402
|
readonly taskFunctionOperationStatus?: boolean;
|
|
285
403
|
/**
|
|
286
|
-
* Task function
|
|
404
|
+
* Task function properties.
|
|
287
405
|
*/
|
|
288
|
-
readonly
|
|
406
|
+
readonly taskFunctionProperties?: TaskFunctionProperties;
|
|
289
407
|
/**
|
|
290
|
-
* Task function
|
|
408
|
+
* Task function serialized to string.
|
|
291
409
|
*/
|
|
292
|
-
readonly
|
|
410
|
+
readonly taskFunction?: string;
|
|
293
411
|
/**
|
|
294
|
-
* Task
|
|
412
|
+
* Task functions properties.
|
|
295
413
|
*/
|
|
296
|
-
readonly
|
|
414
|
+
readonly taskFunctionsProperties?: TaskFunctionProperties[];
|
|
297
415
|
/**
|
|
298
416
|
* Whether the worker computes the given statistics or not.
|
|
299
417
|
*/
|
|
@@ -369,195 +487,40 @@ type TaskAsyncFunction<Data = unknown, Response = unknown> = (data?: Data) => Pr
|
|
|
369
487
|
*/
|
|
370
488
|
type TaskFunction<Data = unknown, Response = unknown> = TaskSyncFunction<Data, Response> | TaskAsyncFunction<Data, Response>;
|
|
371
489
|
/**
|
|
372
|
-
*
|
|
373
|
-
* This object can contain synchronous or asynchronous functions.
|
|
374
|
-
* The key is the name of the function.
|
|
375
|
-
* The value is the function itself.
|
|
490
|
+
* Task function object.
|
|
376
491
|
*
|
|
377
492
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
378
493
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
379
494
|
*/
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Task function operation result.
|
|
383
|
-
*/
|
|
384
|
-
interface TaskFunctionOperationResult {
|
|
385
|
-
status: boolean;
|
|
386
|
-
error?: Error;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Enumeration of worker choice strategies.
|
|
391
|
-
*/
|
|
392
|
-
declare const WorkerChoiceStrategies: Readonly<{
|
|
393
|
-
ROUND_ROBIN: 'ROUND_ROBIN';
|
|
394
|
-
LEAST_USED: 'LEAST_USED';
|
|
395
|
-
LEAST_BUSY: 'LEAST_BUSY';
|
|
396
|
-
LEAST_ELU: 'LEAST_ELU';
|
|
397
|
-
FAIR_SHARE: 'FAIR_SHARE';
|
|
398
|
-
WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN';
|
|
399
|
-
INTERLEAVED_WEIGHTED_ROUND_ROBIN: 'INTERLEAVED_WEIGHTED_ROUND_ROBIN';
|
|
400
|
-
}>;
|
|
401
|
-
/**
|
|
402
|
-
* Worker choice strategy.
|
|
403
|
-
*/
|
|
404
|
-
type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies;
|
|
405
|
-
/**
|
|
406
|
-
* Enumeration of measurements.
|
|
407
|
-
*/
|
|
408
|
-
declare const Measurements: Readonly<{
|
|
409
|
-
runTime: 'runTime';
|
|
410
|
-
waitTime: 'waitTime';
|
|
411
|
-
elu: 'elu';
|
|
412
|
-
}>;
|
|
413
|
-
/**
|
|
414
|
-
* Measurement.
|
|
415
|
-
*/
|
|
416
|
-
type Measurement = keyof typeof Measurements;
|
|
417
|
-
/**
|
|
418
|
-
* Measurement options.
|
|
419
|
-
*/
|
|
420
|
-
interface MeasurementOptions {
|
|
421
|
-
/**
|
|
422
|
-
* Set measurement median.
|
|
423
|
-
*/
|
|
424
|
-
readonly median: boolean;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Worker choice strategy options.
|
|
428
|
-
*/
|
|
429
|
-
interface WorkerChoiceStrategyOptions {
|
|
430
|
-
/**
|
|
431
|
-
* Measurement to use in worker choice strategy supporting it.
|
|
432
|
-
*/
|
|
433
|
-
readonly measurement?: Measurement;
|
|
434
|
-
/**
|
|
435
|
-
* Runtime options.
|
|
436
|
-
*
|
|
437
|
-
* @defaultValue \{ median: false \}
|
|
438
|
-
*/
|
|
439
|
-
readonly runTime?: MeasurementOptions;
|
|
440
|
-
/**
|
|
441
|
-
* Wait time options.
|
|
442
|
-
*
|
|
443
|
-
* @defaultValue \{ median: false \}
|
|
444
|
-
*/
|
|
445
|
-
readonly waitTime?: MeasurementOptions;
|
|
446
|
-
/**
|
|
447
|
-
* Event loop utilization options.
|
|
448
|
-
*
|
|
449
|
-
* @defaultValue \{ median: false \}
|
|
450
|
-
*/
|
|
451
|
-
readonly elu?: MeasurementOptions;
|
|
452
|
-
/**
|
|
453
|
-
* Worker weights to use for weighted round robin worker selection strategies.
|
|
454
|
-
* A weight is tasks maximum execution time in milliseconds for a worker node.
|
|
455
|
-
*
|
|
456
|
-
* @defaultValue Weights computed automatically given the CPU performance.
|
|
457
|
-
*/
|
|
458
|
-
weights?: Record<number, number>;
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Measurement statistics requirements.
|
|
462
|
-
*
|
|
463
|
-
* @internal
|
|
464
|
-
*/
|
|
465
|
-
interface MeasurementStatisticsRequirements {
|
|
495
|
+
interface TaskFunctionObject<Data = unknown, Response = unknown> {
|
|
466
496
|
/**
|
|
467
|
-
*
|
|
497
|
+
* Task function.
|
|
468
498
|
*/
|
|
469
|
-
|
|
499
|
+
taskFunction: TaskFunction<Data, Response>;
|
|
470
500
|
/**
|
|
471
|
-
*
|
|
501
|
+
* Task function priority. Lower values have higher priority.
|
|
472
502
|
*/
|
|
473
|
-
|
|
503
|
+
priority?: number;
|
|
474
504
|
/**
|
|
475
|
-
*
|
|
505
|
+
* Task function worker choice strategy.
|
|
476
506
|
*/
|
|
477
|
-
|
|
507
|
+
strategy?: WorkerChoiceStrategy;
|
|
478
508
|
}
|
|
479
509
|
/**
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*/
|
|
484
|
-
interface TaskStatisticsRequirements {
|
|
485
|
-
/**
|
|
486
|
-
* Tasks runtime requirements.
|
|
487
|
-
*/
|
|
488
|
-
readonly runTime: MeasurementStatisticsRequirements;
|
|
489
|
-
/**
|
|
490
|
-
* Tasks wait time requirements.
|
|
491
|
-
*/
|
|
492
|
-
readonly waitTime: MeasurementStatisticsRequirements;
|
|
493
|
-
/**
|
|
494
|
-
* Tasks event loop utilization requirements.
|
|
495
|
-
*/
|
|
496
|
-
readonly elu: MeasurementStatisticsRequirements;
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Strategy policy.
|
|
510
|
+
* Tasks functions that can be executed.
|
|
511
|
+
* The key is the name of the task function or task function object.
|
|
512
|
+
* The value is the function or task function object.
|
|
500
513
|
*
|
|
501
|
-
* @
|
|
514
|
+
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
515
|
+
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
502
516
|
*/
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Expects tasks execution on the newly created dynamic worker.
|
|
506
|
-
*/
|
|
507
|
-
readonly dynamicWorkerUsage: boolean;
|
|
508
|
-
/**
|
|
509
|
-
* Expects the newly created dynamic worker to be flagged as ready.
|
|
510
|
-
*/
|
|
511
|
-
readonly dynamicWorkerReady: boolean;
|
|
512
|
-
}
|
|
517
|
+
type TaskFunctions<Data = unknown, Response = unknown> = Record<string, TaskFunction<Data, Response> | TaskFunctionObject<Data, Response>>;
|
|
513
518
|
/**
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
* @internal
|
|
519
|
+
* Task function operation result.
|
|
517
520
|
*/
|
|
518
|
-
interface
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
*/
|
|
522
|
-
readonly strategyPolicy: StrategyPolicy;
|
|
523
|
-
/**
|
|
524
|
-
* Tasks statistics requirements.
|
|
525
|
-
*/
|
|
526
|
-
readonly taskStatisticsRequirements: TaskStatisticsRequirements;
|
|
527
|
-
/**
|
|
528
|
-
* Resets strategy internals.
|
|
529
|
-
*
|
|
530
|
-
* @returns `true` if the reset is successful, `false` otherwise.
|
|
531
|
-
*/
|
|
532
|
-
readonly reset: () => boolean;
|
|
533
|
-
/**
|
|
534
|
-
* Updates the worker node key strategy internals.
|
|
535
|
-
* This is called after a task has been executed on a worker node.
|
|
536
|
-
*
|
|
537
|
-
* @returns `true` if the update is successful, `false` otherwise.
|
|
538
|
-
*/
|
|
539
|
-
readonly update: (workerNodeKey: number) => boolean;
|
|
540
|
-
/**
|
|
541
|
-
* Chooses a worker node in the pool and returns its key.
|
|
542
|
-
* If no worker nodes are not eligible, `undefined` is returned.
|
|
543
|
-
* If `undefined` is returned, the caller retry.
|
|
544
|
-
*
|
|
545
|
-
* @returns The worker node key or `undefined`.
|
|
546
|
-
*/
|
|
547
|
-
readonly choose: () => number | undefined;
|
|
548
|
-
/**
|
|
549
|
-
* Removes the worker node key from strategy internals.
|
|
550
|
-
*
|
|
551
|
-
* @param workerNodeKey - The worker node key.
|
|
552
|
-
* @returns `true` if the worker node key is removed, `false` otherwise.
|
|
553
|
-
*/
|
|
554
|
-
readonly remove: (workerNodeKey: number) => boolean;
|
|
555
|
-
/**
|
|
556
|
-
* Sets the worker choice strategy options.
|
|
557
|
-
*
|
|
558
|
-
* @param opts - The worker choice strategy options.
|
|
559
|
-
*/
|
|
560
|
-
readonly setOptions: (opts: WorkerChoiceStrategyOptions | undefined) => void;
|
|
521
|
+
interface TaskFunctionOperationResult {
|
|
522
|
+
status: boolean;
|
|
523
|
+
error?: Error;
|
|
561
524
|
}
|
|
562
525
|
|
|
563
526
|
/**
|
|
@@ -705,9 +668,9 @@ interface WorkerInfo {
|
|
|
705
668
|
*/
|
|
706
669
|
stealing: boolean;
|
|
707
670
|
/**
|
|
708
|
-
* Task
|
|
671
|
+
* Task functions properties.
|
|
709
672
|
*/
|
|
710
|
-
|
|
673
|
+
taskFunctionsProperties?: TaskFunctionProperties[];
|
|
711
674
|
}
|
|
712
675
|
/**
|
|
713
676
|
* Worker usage statistics.
|
|
@@ -795,6 +758,7 @@ interface WorkerNodeOptions {
|
|
|
795
758
|
workerOptions?: WorkerOptions$1;
|
|
796
759
|
env?: Record<string, unknown>;
|
|
797
760
|
tasksQueueBackPressureSize: number | undefined;
|
|
761
|
+
tasksQueueBucketSize: number | undefined;
|
|
798
762
|
}
|
|
799
763
|
/**
|
|
800
764
|
* Worker node interface.
|
|
@@ -843,25 +807,13 @@ interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitt
|
|
|
843
807
|
* @returns The tasks queue size.
|
|
844
808
|
*/
|
|
845
809
|
readonly enqueueTask: (task: Task<Data>) => number;
|
|
846
|
-
/**
|
|
847
|
-
* Prepends a task to the tasks queue.
|
|
848
|
-
*
|
|
849
|
-
* @param task - The task to prepend.
|
|
850
|
-
* @returns The tasks queue size.
|
|
851
|
-
*/
|
|
852
|
-
readonly unshiftTask: (task: Task<Data>) => number;
|
|
853
810
|
/**
|
|
854
811
|
* Dequeue task.
|
|
855
812
|
*
|
|
813
|
+
* @param bucket - The prioritized bucket to dequeue from. @defaultValue 0
|
|
856
814
|
* @returns The dequeued task.
|
|
857
815
|
*/
|
|
858
|
-
readonly dequeueTask: () => Task<Data> | undefined;
|
|
859
|
-
/**
|
|
860
|
-
* Pops a task from the tasks queue.
|
|
861
|
-
*
|
|
862
|
-
* @returns The popped task.
|
|
863
|
-
*/
|
|
864
|
-
readonly popTask: () => Task<Data> | undefined;
|
|
816
|
+
readonly dequeueTask: (bucket?: number) => Task<Data> | undefined;
|
|
865
817
|
/**
|
|
866
818
|
* Clears tasks queue.
|
|
867
819
|
*/
|
|
@@ -872,10 +824,6 @@ interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitt
|
|
|
872
824
|
* @returns `true` if the worker node has back pressure, `false` otherwise.
|
|
873
825
|
*/
|
|
874
826
|
readonly hasBackPressure: () => boolean;
|
|
875
|
-
/**
|
|
876
|
-
* Resets usage statistics.
|
|
877
|
-
*/
|
|
878
|
-
readonly resetUsage: () => void;
|
|
879
827
|
/**
|
|
880
828
|
* Terminates the worker node.
|
|
881
829
|
*/
|
|
@@ -956,7 +904,7 @@ interface PoolInfo {
|
|
|
956
904
|
readonly worker: WorkerType;
|
|
957
905
|
readonly started: boolean;
|
|
958
906
|
readonly ready: boolean;
|
|
959
|
-
readonly
|
|
907
|
+
readonly defaultStrategy: WorkerChoiceStrategy;
|
|
960
908
|
readonly strategyRetries: number;
|
|
961
909
|
readonly minSize: number;
|
|
962
910
|
readonly maxSize: number;
|
|
@@ -1062,7 +1010,7 @@ interface PoolOptions<Worker extends IWorker> {
|
|
|
1062
1010
|
*/
|
|
1063
1011
|
startWorkers?: boolean;
|
|
1064
1012
|
/**
|
|
1065
|
-
* The worker choice strategy to use in this pool.
|
|
1013
|
+
* The default worker choice strategy to use in this pool.
|
|
1066
1014
|
*
|
|
1067
1015
|
* @defaultValue WorkerChoiceStrategies.ROUND_ROBIN
|
|
1068
1016
|
*/
|
|
@@ -1187,11 +1135,11 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1187
1135
|
*/
|
|
1188
1136
|
readonly removeTaskFunction: (name: string) => Promise<boolean>;
|
|
1189
1137
|
/**
|
|
1190
|
-
* Lists the
|
|
1138
|
+
* Lists the properties of task functions available in this pool.
|
|
1191
1139
|
*
|
|
1192
|
-
* @returns The
|
|
1140
|
+
* @returns The properties of task functions available in this pool.
|
|
1193
1141
|
*/
|
|
1194
|
-
readonly
|
|
1142
|
+
readonly listTaskFunctionsProperties: () => TaskFunctionProperties[];
|
|
1195
1143
|
/**
|
|
1196
1144
|
* Sets the default task function in this pool.
|
|
1197
1145
|
*
|
|
@@ -1200,9 +1148,9 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1200
1148
|
*/
|
|
1201
1149
|
readonly setDefaultTaskFunction: (name: string) => Promise<boolean>;
|
|
1202
1150
|
/**
|
|
1203
|
-
* Sets the worker choice strategy in this pool.
|
|
1151
|
+
* Sets the default worker choice strategy in this pool.
|
|
1204
1152
|
*
|
|
1205
|
-
* @param workerChoiceStrategy - The worker choice strategy.
|
|
1153
|
+
* @param workerChoiceStrategy - The default worker choice strategy.
|
|
1206
1154
|
* @param workerChoiceStrategyOptions - The worker choice strategy options.
|
|
1207
1155
|
*/
|
|
1208
1156
|
readonly setWorkerChoiceStrategy: (workerChoiceStrategy: WorkerChoiceStrategy, workerChoiceStrategyOptions?: WorkerChoiceStrategyOptions) => void;
|
|
@@ -1210,8 +1158,9 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1210
1158
|
* Sets the worker choice strategy options in this pool.
|
|
1211
1159
|
*
|
|
1212
1160
|
* @param workerChoiceStrategyOptions - The worker choice strategy options.
|
|
1161
|
+
* @returns `true` if the worker choice strategy options were set, `false` otherwise.
|
|
1213
1162
|
*/
|
|
1214
|
-
readonly setWorkerChoiceStrategyOptions: (workerChoiceStrategyOptions: WorkerChoiceStrategyOptions) =>
|
|
1163
|
+
readonly setWorkerChoiceStrategyOptions: (workerChoiceStrategyOptions: WorkerChoiceStrategyOptions) => boolean;
|
|
1215
1164
|
/**
|
|
1216
1165
|
* Enables/disables the worker node tasks queue in this pool.
|
|
1217
1166
|
*
|
|
@@ -1228,65 +1177,79 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1228
1177
|
}
|
|
1229
1178
|
|
|
1230
1179
|
/**
|
|
1231
|
-
* The worker choice
|
|
1180
|
+
* The worker choice strategies context.
|
|
1232
1181
|
*
|
|
1233
1182
|
* @typeParam Worker - Type of worker.
|
|
1234
1183
|
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1235
1184
|
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
1236
1185
|
*/
|
|
1237
|
-
declare class
|
|
1238
|
-
private
|
|
1186
|
+
declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
1187
|
+
private readonly pool;
|
|
1239
1188
|
/**
|
|
1240
|
-
* The number of worker choice
|
|
1189
|
+
* The number of worker choice strategies execution retries.
|
|
1241
1190
|
*/
|
|
1242
1191
|
retriesCount: number;
|
|
1243
1192
|
/**
|
|
1244
|
-
* The worker choice strategy
|
|
1193
|
+
* The default worker choice strategy in the context.
|
|
1194
|
+
*/
|
|
1195
|
+
private defaultWorkerChoiceStrategy;
|
|
1196
|
+
/**
|
|
1197
|
+
* The worker choice strategies registered in the context.
|
|
1245
1198
|
*/
|
|
1246
1199
|
private readonly workerChoiceStrategies;
|
|
1247
1200
|
/**
|
|
1248
|
-
* The
|
|
1201
|
+
* The active worker choice strategies in the context policy.
|
|
1202
|
+
*/
|
|
1203
|
+
private workerChoiceStrategiesPolicy;
|
|
1204
|
+
/**
|
|
1205
|
+
* The active worker choice strategies in the context task statistics requirements.
|
|
1206
|
+
*/
|
|
1207
|
+
private workerChoiceStrategiesTaskStatisticsRequirements;
|
|
1208
|
+
/**
|
|
1209
|
+
* The maximum number of worker choice strategies execution retries.
|
|
1249
1210
|
*/
|
|
1250
1211
|
private readonly retries;
|
|
1251
1212
|
/**
|
|
1252
|
-
* Worker choice
|
|
1213
|
+
* Worker choice strategies context constructor.
|
|
1253
1214
|
*
|
|
1254
1215
|
* @param pool - The pool instance.
|
|
1255
|
-
* @param
|
|
1216
|
+
* @param workerChoiceStrategies - The worker choice strategies. @defaultValue [WorkerChoiceStrategies.ROUND_ROBIN]
|
|
1256
1217
|
* @param opts - The worker choice strategy options.
|
|
1257
1218
|
*/
|
|
1258
|
-
constructor(pool: IPool<Worker, Data, Response>,
|
|
1219
|
+
constructor(pool: IPool<Worker, Data, Response>, workerChoiceStrategies?: WorkerChoiceStrategy[], opts?: WorkerChoiceStrategyOptions);
|
|
1259
1220
|
/**
|
|
1260
|
-
* Gets the
|
|
1221
|
+
* Gets the active worker choice strategies in the context policy.
|
|
1261
1222
|
*
|
|
1262
|
-
* @returns The
|
|
1223
|
+
* @returns The strategies policy.
|
|
1263
1224
|
*/
|
|
1264
|
-
|
|
1225
|
+
getPolicy(): StrategyPolicy;
|
|
1265
1226
|
/**
|
|
1266
|
-
* Gets the worker choice
|
|
1227
|
+
* Gets the active worker choice strategies in the context task statistics requirements.
|
|
1267
1228
|
*
|
|
1268
|
-
* @returns The task statistics requirements.
|
|
1229
|
+
* @returns The strategies task statistics requirements.
|
|
1269
1230
|
*/
|
|
1270
1231
|
getTaskStatisticsRequirements(): TaskStatisticsRequirements;
|
|
1271
1232
|
/**
|
|
1272
|
-
* Sets the worker choice strategy to use in the context.
|
|
1233
|
+
* Sets the default worker choice strategy to use in the context.
|
|
1273
1234
|
*
|
|
1274
|
-
* @param workerChoiceStrategy - The worker choice strategy to set.
|
|
1235
|
+
* @param workerChoiceStrategy - The default worker choice strategy to set.
|
|
1236
|
+
* @param opts - The worker choice strategy options.
|
|
1275
1237
|
*/
|
|
1276
|
-
|
|
1238
|
+
setDefaultWorkerChoiceStrategy(workerChoiceStrategy: WorkerChoiceStrategy, opts?: WorkerChoiceStrategyOptions): void;
|
|
1277
1239
|
/**
|
|
1278
|
-
* Updates the worker node key in the worker choice
|
|
1240
|
+
* Updates the worker node key in the active worker choice strategies in the context internals.
|
|
1279
1241
|
*
|
|
1280
1242
|
* @returns `true` if the update is successful, `false` otherwise.
|
|
1281
1243
|
*/
|
|
1282
1244
|
update(workerNodeKey: number): boolean;
|
|
1283
1245
|
/**
|
|
1284
|
-
* Executes the worker choice strategy in the context algorithm.
|
|
1246
|
+
* Executes the given worker choice strategy in the context algorithm.
|
|
1285
1247
|
*
|
|
1248
|
+
* @param workerChoiceStrategy - The worker choice strategy algorithm to execute. @defaultValue this.defaultWorkerChoiceStrategy
|
|
1286
1249
|
* @returns The key of the worker node.
|
|
1287
1250
|
* @throws {@link https://nodejs.org/api/errors.html#class-error} If after computed retries the worker node key is null or undefined.
|
|
1288
1251
|
*/
|
|
1289
|
-
execute(): number;
|
|
1252
|
+
execute(workerChoiceStrategy?: WorkerChoiceStrategy): number;
|
|
1290
1253
|
/**
|
|
1291
1254
|
* Executes the given worker choice strategy.
|
|
1292
1255
|
*
|
|
@@ -1296,18 +1259,40 @@ declare class WorkerChoiceStrategyContext<Worker extends IWorker, Data = unknown
|
|
|
1296
1259
|
*/
|
|
1297
1260
|
private executeStrategy;
|
|
1298
1261
|
/**
|
|
1299
|
-
* Removes the worker node key from the worker choice
|
|
1262
|
+
* Removes the worker node key from the active worker choice strategies in the context.
|
|
1300
1263
|
*
|
|
1301
1264
|
* @param workerNodeKey - The worker node key.
|
|
1302
1265
|
* @returns `true` if the removal is successful, `false` otherwise.
|
|
1303
1266
|
*/
|
|
1304
1267
|
remove(workerNodeKey: number): boolean;
|
|
1305
1268
|
/**
|
|
1306
|
-
* Sets the worker choice strategies in the context options.
|
|
1269
|
+
* Sets the active worker choice strategies in the context options.
|
|
1307
1270
|
*
|
|
1308
1271
|
* @param opts - The worker choice strategy options.
|
|
1309
1272
|
*/
|
|
1310
1273
|
setOptions(opts: WorkerChoiceStrategyOptions | undefined): void;
|
|
1274
|
+
/**
|
|
1275
|
+
* Synchronizes the active worker choice strategies in the context with the given worker choice strategies.
|
|
1276
|
+
*
|
|
1277
|
+
* @param workerChoiceStrategies - The worker choice strategies to synchronize.
|
|
1278
|
+
* @param opts - The worker choice strategy options.
|
|
1279
|
+
*/
|
|
1280
|
+
syncWorkerChoiceStrategies(workerChoiceStrategies: Set<WorkerChoiceStrategy>, opts?: WorkerChoiceStrategyOptions): void;
|
|
1281
|
+
/**
|
|
1282
|
+
* Adds a worker choice strategy to the context.
|
|
1283
|
+
*
|
|
1284
|
+
* @param workerChoiceStrategy - The worker choice strategy to add.
|
|
1285
|
+
* @param opts - The worker choice strategy options.
|
|
1286
|
+
* @returns The worker choice strategies.
|
|
1287
|
+
*/
|
|
1288
|
+
private addWorkerChoiceStrategy;
|
|
1289
|
+
/**
|
|
1290
|
+
* Removes a worker choice strategy from the context.
|
|
1291
|
+
*
|
|
1292
|
+
* @param workerChoiceStrategy - The worker choice strategy to remove.
|
|
1293
|
+
* @returns `true` if the worker choice strategy is removed, `false` otherwise.
|
|
1294
|
+
*/
|
|
1295
|
+
private removeWorkerChoiceStrategy;
|
|
1311
1296
|
}
|
|
1312
1297
|
|
|
1313
1298
|
/**
|
|
@@ -1329,19 +1314,19 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1329
1314
|
/**
|
|
1330
1315
|
* The task execution response promise map:
|
|
1331
1316
|
* - `key`: The message id of each submitted task.
|
|
1332
|
-
* - `value`: An object that contains
|
|
1317
|
+
* - `value`: An object that contains task's worker node key, execution response promise resolve and reject callbacks, async resource.
|
|
1333
1318
|
*
|
|
1334
1319
|
* When we receive a message from the worker, we get a map entry with the promise resolve/reject bound to the message id.
|
|
1335
1320
|
*/
|
|
1336
1321
|
protected promiseResponseMap: Map<string, PromiseResponseWrapper<Response>>;
|
|
1337
1322
|
/**
|
|
1338
|
-
* Worker choice
|
|
1323
|
+
* Worker choice strategies context referencing worker choice algorithms implementation.
|
|
1339
1324
|
*/
|
|
1340
|
-
protected
|
|
1325
|
+
protected workerChoiceStrategiesContext?: WorkerChoiceStrategiesContext<Worker, Data, Response>;
|
|
1341
1326
|
/**
|
|
1342
1327
|
* The task functions added at runtime map:
|
|
1343
1328
|
* - `key`: The task function name.
|
|
1344
|
-
* - `value`: The task function
|
|
1329
|
+
* - `value`: The task function object.
|
|
1345
1330
|
*/
|
|
1346
1331
|
private readonly taskFunctions;
|
|
1347
1332
|
/**
|
|
@@ -1367,7 +1352,7 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1367
1352
|
/**
|
|
1368
1353
|
* The start timestamp of the pool.
|
|
1369
1354
|
*/
|
|
1370
|
-
private
|
|
1355
|
+
private startTimestamp?;
|
|
1371
1356
|
/**
|
|
1372
1357
|
* Constructs a new poolifier pool.
|
|
1373
1358
|
*
|
|
@@ -1425,7 +1410,7 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1425
1410
|
/** @inheritDoc */
|
|
1426
1411
|
setWorkerChoiceStrategy(workerChoiceStrategy: WorkerChoiceStrategy, workerChoiceStrategyOptions?: WorkerChoiceStrategyOptions): void;
|
|
1427
1412
|
/** @inheritDoc */
|
|
1428
|
-
setWorkerChoiceStrategyOptions(workerChoiceStrategyOptions: WorkerChoiceStrategyOptions | undefined):
|
|
1413
|
+
setWorkerChoiceStrategyOptions(workerChoiceStrategyOptions: WorkerChoiceStrategyOptions | undefined): boolean;
|
|
1429
1414
|
/** @inheritDoc */
|
|
1430
1415
|
enableTasksQueue(enable: boolean, tasksQueueOptions?: TasksQueueOptions): void;
|
|
1431
1416
|
/** @inheritDoc */
|
|
@@ -1460,11 +1445,32 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1460
1445
|
/** @inheritDoc */
|
|
1461
1446
|
hasTaskFunction(name: string): boolean;
|
|
1462
1447
|
/** @inheritDoc */
|
|
1463
|
-
addTaskFunction(name: string, fn: TaskFunction<Data, Response>): Promise<boolean>;
|
|
1448
|
+
addTaskFunction(name: string, fn: TaskFunction<Data, Response> | TaskFunctionObject<Data, Response>): Promise<boolean>;
|
|
1464
1449
|
/** @inheritDoc */
|
|
1465
1450
|
removeTaskFunction(name: string): Promise<boolean>;
|
|
1466
1451
|
/** @inheritDoc */
|
|
1467
|
-
|
|
1452
|
+
listTaskFunctionsProperties(): TaskFunctionProperties[];
|
|
1453
|
+
/**
|
|
1454
|
+
* Gets task function strategy, if any.
|
|
1455
|
+
*
|
|
1456
|
+
* @param name - The task function name.
|
|
1457
|
+
* @returns The task function worker choice strategy if the task function worker choice strategy is defined, `undefined` otherwise.
|
|
1458
|
+
*/
|
|
1459
|
+
private readonly getTaskFunctionWorkerWorkerChoiceStrategy;
|
|
1460
|
+
/**
|
|
1461
|
+
* Gets worker node task function priority, if any.
|
|
1462
|
+
*
|
|
1463
|
+
* @param workerNodeKey - The worker node key.
|
|
1464
|
+
* @param name - The task function name.
|
|
1465
|
+
* @returns The task function worker choice priority if the task function worker choice priority is defined, `undefined` otherwise.
|
|
1466
|
+
*/
|
|
1467
|
+
private readonly getWorkerNodeTaskFunctionPriority;
|
|
1468
|
+
/**
|
|
1469
|
+
* Gets the worker choice strategies registered in this pool.
|
|
1470
|
+
*
|
|
1471
|
+
* @returns The worker choice strategies.
|
|
1472
|
+
*/
|
|
1473
|
+
private readonly getWorkerWorkerChoiceStrategies;
|
|
1468
1474
|
/** @inheritDoc */
|
|
1469
1475
|
setDefaultTaskFunction(name: string): Promise<boolean>;
|
|
1470
1476
|
private deleteTaskFunctionWorkerUsages;
|
|
@@ -1523,10 +1529,9 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1523
1529
|
*/
|
|
1524
1530
|
private shallUpdateTaskFunctionWorkerUsage;
|
|
1525
1531
|
/**
|
|
1526
|
-
* Chooses a worker node for the next task.
|
|
1527
|
-
*
|
|
1528
|
-
* The default worker choice strategy uses a round robin algorithm to distribute the tasks.
|
|
1532
|
+
* Chooses a worker node for the next task given the worker choice strategy.
|
|
1529
1533
|
*
|
|
1534
|
+
* @param workerChoiceStrategy - The worker choice strategy.
|
|
1530
1535
|
* @returns The chosen worker node key
|
|
1531
1536
|
*/
|
|
1532
1537
|
private chooseWorkerNode;
|
|
@@ -1818,6 +1823,80 @@ declare class DynamicThreadPool<Data = unknown, Response = unknown> extends Fixe
|
|
|
1818
1823
|
protected get busy(): boolean;
|
|
1819
1824
|
}
|
|
1820
1825
|
|
|
1826
|
+
/**
|
|
1827
|
+
* Priority queue node.
|
|
1828
|
+
*
|
|
1829
|
+
* @typeParam T - Type of priority queue node data.
|
|
1830
|
+
* @internal
|
|
1831
|
+
*/
|
|
1832
|
+
interface PriorityQueueNode<T> {
|
|
1833
|
+
data: T;
|
|
1834
|
+
priority: number;
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Priority queue.
|
|
1838
|
+
*
|
|
1839
|
+
* @typeParam T - Type of priority queue data.
|
|
1840
|
+
* @internal
|
|
1841
|
+
*/
|
|
1842
|
+
declare class PriorityQueue<T> {
|
|
1843
|
+
private nodeArray;
|
|
1844
|
+
/** Prioritized bucket size. */
|
|
1845
|
+
private readonly k;
|
|
1846
|
+
/** The size of the priority queue. */
|
|
1847
|
+
size: number;
|
|
1848
|
+
/** The maximum size of the priority queue. */
|
|
1849
|
+
maxSize: number;
|
|
1850
|
+
/**
|
|
1851
|
+
* Constructs a priority queue.
|
|
1852
|
+
*
|
|
1853
|
+
* @param k - Prioritized bucket size. @defaultValue Infinity
|
|
1854
|
+
*/
|
|
1855
|
+
constructor(k?: number);
|
|
1856
|
+
/**
|
|
1857
|
+
* Enqueue data into the priority queue.
|
|
1858
|
+
*
|
|
1859
|
+
* @param data - Data to enqueue.
|
|
1860
|
+
* @param priority - Priority of the data. Lower values have higher priority.
|
|
1861
|
+
* @returns The new size of the priority queue.
|
|
1862
|
+
*/
|
|
1863
|
+
enqueue(data: T, priority?: number): number;
|
|
1864
|
+
/**
|
|
1865
|
+
* Dequeue data from the priority queue.
|
|
1866
|
+
*
|
|
1867
|
+
* @param bucket - The prioritized bucket to dequeue from. @defaultValue 0
|
|
1868
|
+
* @returns The dequeued data or `undefined` if the priority queue is empty.
|
|
1869
|
+
*/
|
|
1870
|
+
dequeue(bucket?: number): T | undefined;
|
|
1871
|
+
/**
|
|
1872
|
+
* Peeks at the first data.
|
|
1873
|
+
* @returns The first data or `undefined` if the priority queue is empty.
|
|
1874
|
+
*/
|
|
1875
|
+
peekFirst(): T | undefined;
|
|
1876
|
+
/**
|
|
1877
|
+
* Peeks at the last data.
|
|
1878
|
+
* @returns The last data or `undefined` if the priority queue is empty.
|
|
1879
|
+
*/
|
|
1880
|
+
peekLast(): T | undefined;
|
|
1881
|
+
/**
|
|
1882
|
+
* Clears the priority queue.
|
|
1883
|
+
*/
|
|
1884
|
+
clear(): void;
|
|
1885
|
+
/**
|
|
1886
|
+
* Returns an iterator for the priority queue.
|
|
1887
|
+
*
|
|
1888
|
+
* @returns An iterator for the priority queue.
|
|
1889
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
|
|
1890
|
+
*/
|
|
1891
|
+
[Symbol.iterator](): Iterator<T>;
|
|
1892
|
+
/**
|
|
1893
|
+
* Increments the size of the priority queue.
|
|
1894
|
+
*
|
|
1895
|
+
* @returns The new size of the priority queue.
|
|
1896
|
+
*/
|
|
1897
|
+
private incrementSize;
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1821
1900
|
/**
|
|
1822
1901
|
* Returns safe host OS optimized estimate of the default amount of parallelism a pool should use.
|
|
1823
1902
|
* Always returns a value greater than zero.
|
|
@@ -1842,9 +1921,9 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
1842
1921
|
*/
|
|
1843
1922
|
protected abstract id: number;
|
|
1844
1923
|
/**
|
|
1845
|
-
* Task function(s) processed by the worker when the pool's `execution` function is invoked.
|
|
1924
|
+
* Task function object(s) processed by the worker when the pool's `execution` function is invoked.
|
|
1846
1925
|
*/
|
|
1847
|
-
protected taskFunctions: Map<string,
|
|
1926
|
+
protected taskFunctions: Map<string, TaskFunctionObject<Data, Response>>;
|
|
1848
1927
|
/**
|
|
1849
1928
|
* Timestamp of the last task processed by this worker.
|
|
1850
1929
|
*/
|
|
@@ -1888,7 +1967,7 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
1888
1967
|
* @param fn - The task function to add.
|
|
1889
1968
|
* @returns Whether the task function was added or not.
|
|
1890
1969
|
*/
|
|
1891
|
-
addTaskFunction(name: string, fn: TaskFunction<Data, Response>): TaskFunctionOperationResult;
|
|
1970
|
+
addTaskFunction(name: string, fn: TaskFunction<Data, Response> | TaskFunctionObject<Data, Response>): TaskFunctionOperationResult;
|
|
1892
1971
|
/**
|
|
1893
1972
|
* Removes a task function from the worker.
|
|
1894
1973
|
*
|
|
@@ -1897,11 +1976,11 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
1897
1976
|
*/
|
|
1898
1977
|
removeTaskFunction(name: string): TaskFunctionOperationResult;
|
|
1899
1978
|
/**
|
|
1900
|
-
* Lists the
|
|
1979
|
+
* Lists the properties of the worker's task functions.
|
|
1901
1980
|
*
|
|
1902
|
-
* @returns The
|
|
1981
|
+
* @returns The properties of the worker's task functions.
|
|
1903
1982
|
*/
|
|
1904
|
-
|
|
1983
|
+
listTaskFunctionsProperties(): TaskFunctionProperties[];
|
|
1905
1984
|
/**
|
|
1906
1985
|
* Sets the default task function to use in the worker.
|
|
1907
1986
|
*
|
|
@@ -1961,9 +2040,9 @@ declare abstract class AbstractWorker<MainWorker extends Worker | MessagePort, D
|
|
|
1961
2040
|
*/
|
|
1962
2041
|
protected abstract sendToMainWorker(message: MessageValue<Response, Data>): void;
|
|
1963
2042
|
/**
|
|
1964
|
-
* Sends task
|
|
2043
|
+
* Sends task functions properties to the main worker.
|
|
1965
2044
|
*/
|
|
1966
|
-
protected
|
|
2045
|
+
protected sendTaskFunctionsPropertiesToMainWorker(): void;
|
|
1967
2046
|
/**
|
|
1968
2047
|
* Handles an error and convert it to a string so it can be sent back to the main worker.
|
|
1969
2048
|
*
|
|
@@ -2067,4 +2146,4 @@ declare class ThreadWorker<Data = unknown, Response = unknown> extends AbstractW
|
|
|
2067
2146
|
protected handleError(error: Error | string): string;
|
|
2068
2147
|
}
|
|
2069
2148
|
|
|
2070
|
-
export { AbstractPool, AbstractWorker, CircularArray, type ClusterPoolOptions, ClusterWorker,
|
|
2149
|
+
export { AbstractPool, AbstractWorker, CircularArray, type ClusterPoolOptions, ClusterWorker, DynamicClusterPool, DynamicThreadPool, type ErrorHandler, type EventHandler, type EventLoopUtilizationMeasurementStatistics, type ExitHandler, FixedClusterPool, FixedThreadPool, type IPool, type IWorker, type IWorkerChoiceStrategy, type IWorkerNode, type KillBehavior, KillBehaviors, type KillHandler, type Measurement, type MeasurementOptions, type MeasurementStatistics, type MeasurementStatisticsRequirements, Measurements, type MessageHandler, type MessageValue, type OnlineHandler, type PoolEvent, PoolEvents, type PoolInfo, type PoolOptions, type PoolType, PoolTypes, PriorityQueue, type PriorityQueueNode, type PromiseResponseWrapper, type StrategyData, type StrategyPolicy, type Task, type TaskAsyncFunction, type TaskFunction, type TaskFunctionObject, type TaskFunctionOperationResult, type TaskFunctionProperties, type TaskFunctions, type TaskPerformance, type TaskStatistics, type TaskStatisticsRequirements, type TaskSyncFunction, type TasksQueueOptions, type ThreadPoolOptions, ThreadWorker, WorkerChoiceStrategies, WorkerChoiceStrategiesContext, type WorkerChoiceStrategy, type WorkerChoiceStrategyOptions, type WorkerError, type WorkerInfo, type WorkerNodeEventDetail, type WorkerNodeOptions, type WorkerOptions, type WorkerStatistics, type WorkerType, WorkerTypes, type WorkerUsage, type Writable, availableParallelism };
|