poolifier 5.1.6 → 5.2.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 +1 -0
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +104 -75
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -15,7 +15,9 @@ declare class CircularBuffer {
|
|
|
15
15
|
private readIdx;
|
|
16
16
|
private writeIdx;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* CircularBuffer constructor.
|
|
19
|
+
* @param size - Buffer size.
|
|
20
|
+
* @defaultValue defaultBufferSize
|
|
19
21
|
* @returns CircularBuffer.
|
|
20
22
|
*/
|
|
21
23
|
constructor(size?: number);
|
|
@@ -86,11 +88,11 @@ declare const Measurements: Readonly<{
|
|
|
86
88
|
interface IWorkerChoiceStrategy {
|
|
87
89
|
/**
|
|
88
90
|
* Chooses a worker node in the pool and returns its key.
|
|
89
|
-
* If no worker nodes are
|
|
90
|
-
* If
|
|
91
|
+
* If no worker nodes are eligible, `undefined` is returned and the caller retries.
|
|
92
|
+
* @param workerNodeKeysSet - The worker node keys affinity set. If undefined, all workers are eligible.
|
|
91
93
|
* @returns The worker node key or `undefined`.
|
|
92
94
|
*/
|
|
93
|
-
readonly choose: () => number | undefined;
|
|
95
|
+
readonly choose: (workerNodeKeysSet?: ReadonlySet<number>) => number | undefined;
|
|
94
96
|
/**
|
|
95
97
|
* The worker choice strategy name.
|
|
96
98
|
*/
|
|
@@ -274,8 +276,8 @@ interface WorkerOptions {
|
|
|
274
276
|
|
|
275
277
|
/**
|
|
276
278
|
* Message object that is passed between main worker and worker.
|
|
277
|
-
* @
|
|
278
|
-
* @
|
|
279
|
+
* @template Data - Type of data sent to the worker or execution response. This can only be structured-cloneable data.
|
|
280
|
+
* @template ErrorData - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
|
|
279
281
|
* @internal
|
|
280
282
|
*/
|
|
281
283
|
interface MessageValue<Data = unknown, ErrorData = unknown> extends Task<Data> {
|
|
@@ -342,7 +344,7 @@ interface MessageValue<Data = unknown, ErrorData = unknown> extends Task<Data> {
|
|
|
342
344
|
}
|
|
343
345
|
/**
|
|
344
346
|
* An object holding the task execution response promise resolve/reject callbacks.
|
|
345
|
-
* @
|
|
347
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
346
348
|
* @internal
|
|
347
349
|
*/
|
|
348
350
|
interface PromiseResponseWrapper<Response = unknown> {
|
|
@@ -369,7 +371,7 @@ interface PromiseResponseWrapper<Response = unknown> {
|
|
|
369
371
|
}
|
|
370
372
|
/**
|
|
371
373
|
* Message object that is passed as a task between main worker and worker.
|
|
372
|
-
* @
|
|
374
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
373
375
|
* @internal
|
|
374
376
|
*/
|
|
375
377
|
interface Task<Data = unknown> {
|
|
@@ -423,6 +425,13 @@ interface TaskFunctionProperties {
|
|
|
423
425
|
* Task function worker choice strategy.
|
|
424
426
|
*/
|
|
425
427
|
readonly strategy?: WorkerChoiceStrategy;
|
|
428
|
+
/**
|
|
429
|
+
* Task function worker node keys affinity.
|
|
430
|
+
* Restricts task execution to specified worker nodes by their indices.
|
|
431
|
+
* Must contain valid indices within [0, pool max size - 1].
|
|
432
|
+
* If undefined, task can execute on any worker node.
|
|
433
|
+
*/
|
|
434
|
+
readonly workerNodeKeys?: number[];
|
|
426
435
|
}
|
|
427
436
|
/**
|
|
428
437
|
* Task performance.
|
|
@@ -448,7 +457,7 @@ interface TaskPerformance {
|
|
|
448
457
|
}
|
|
449
458
|
/**
|
|
450
459
|
* Worker error.
|
|
451
|
-
* @
|
|
460
|
+
* @template Data - Type of data sent to the worker triggering an error. This can only be structured-cloneable data.
|
|
452
461
|
*/
|
|
453
462
|
interface WorkerError<Data = unknown> {
|
|
454
463
|
/**
|
|
@@ -492,7 +501,7 @@ interface WorkerStatistics {
|
|
|
492
501
|
}
|
|
493
502
|
/**
|
|
494
503
|
* Remove readonly modifier from all properties of T.
|
|
495
|
-
* @
|
|
504
|
+
* @template T - Type to remove readonly modifier.
|
|
496
505
|
* @internal
|
|
497
506
|
*/
|
|
498
507
|
type Writable<T> = {
|
|
@@ -504,21 +513,21 @@ type Writable<T> = {
|
|
|
504
513
|
* This function must return a promise.
|
|
505
514
|
* @param data - Data sent to the worker.
|
|
506
515
|
* @returns Execution response promise.
|
|
507
|
-
* @
|
|
508
|
-
* @
|
|
516
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
517
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
509
518
|
*/
|
|
510
519
|
type TaskAsyncFunction<Data = unknown, Response = unknown> = (data?: Data) => Promise<Response>;
|
|
511
520
|
/**
|
|
512
521
|
* Task function that can be executed.
|
|
513
522
|
* This function can be synchronous or asynchronous.
|
|
514
|
-
* @
|
|
515
|
-
* @
|
|
523
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
524
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
516
525
|
*/
|
|
517
526
|
type TaskFunction<Data = unknown, Response = unknown> = TaskAsyncFunction<Data, Response> | TaskSyncFunction<Data, Response>;
|
|
518
527
|
/**
|
|
519
528
|
* Task function object.
|
|
520
|
-
* @
|
|
521
|
-
* @
|
|
529
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
530
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
522
531
|
*/
|
|
523
532
|
interface TaskFunctionObject<Data = unknown, Response = unknown> {
|
|
524
533
|
/**
|
|
@@ -533,6 +542,13 @@ interface TaskFunctionObject<Data = unknown, Response = unknown> {
|
|
|
533
542
|
* Task function.
|
|
534
543
|
*/
|
|
535
544
|
taskFunction: TaskFunction<Data, Response>;
|
|
545
|
+
/**
|
|
546
|
+
* Task function worker node keys affinity.
|
|
547
|
+
* Restricts task execution to specified worker nodes by their indices.
|
|
548
|
+
* Must contain valid indices within [0, pool max size - 1].
|
|
549
|
+
* If undefined, task can execute on any worker node.
|
|
550
|
+
*/
|
|
551
|
+
workerNodeKeys?: number[];
|
|
536
552
|
}
|
|
537
553
|
/**
|
|
538
554
|
* Task function operation result.
|
|
@@ -545,22 +561,22 @@ interface TaskFunctionOperationResult {
|
|
|
545
561
|
* Tasks functions that can be executed.
|
|
546
562
|
* The key is the name of the task function or task function object.
|
|
547
563
|
* The value is the task function or task function object.
|
|
548
|
-
* @
|
|
549
|
-
* @
|
|
564
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
565
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
550
566
|
*/
|
|
551
567
|
type TaskFunctions<Data = unknown, Response = unknown> = Record<string, TaskFunction<Data, Response> | TaskFunctionObject<Data, Response>>;
|
|
552
568
|
/**
|
|
553
569
|
* Task synchronous function that can be executed.
|
|
554
570
|
* @param data - Data sent to the worker.
|
|
555
571
|
* @returns Execution response.
|
|
556
|
-
* @
|
|
557
|
-
* @
|
|
572
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
573
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
558
574
|
*/
|
|
559
575
|
type TaskSyncFunction<Data = unknown, Response = unknown> = (data?: Data) => Response;
|
|
560
576
|
|
|
561
577
|
/**
|
|
562
578
|
* Priority queue.
|
|
563
|
-
* @
|
|
579
|
+
* @template T - Type of priority queue data.
|
|
564
580
|
* @internal
|
|
565
581
|
*/
|
|
566
582
|
declare class PriorityQueue<T> {
|
|
@@ -589,8 +605,10 @@ declare class PriorityQueue<T> {
|
|
|
589
605
|
private tail;
|
|
590
606
|
/**
|
|
591
607
|
* Constructs a priority queue.
|
|
592
|
-
* @param bucketSize - Prioritized bucket size.
|
|
593
|
-
* @
|
|
608
|
+
* @param bucketSize - Prioritized bucket size.
|
|
609
|
+
* @defaultValue defaultBucketSize
|
|
610
|
+
* @param enablePriority - Whether to enable priority.
|
|
611
|
+
* @defaultValue false
|
|
594
612
|
* @returns PriorityQueue.
|
|
595
613
|
*/
|
|
596
614
|
constructor(bucketSize?: number, enablePriority?: boolean);
|
|
@@ -629,27 +647,27 @@ declare class PriorityQueue<T> {
|
|
|
629
647
|
|
|
630
648
|
/**
|
|
631
649
|
* Callback invoked if the worker raised an error.
|
|
632
|
-
* @
|
|
650
|
+
* @template Worker - Type of worker.
|
|
633
651
|
*/
|
|
634
652
|
type ErrorHandler<Worker extends IWorker> = (this: Worker, error: Error) => void;
|
|
635
653
|
/**
|
|
636
654
|
* Worker event handler.
|
|
637
|
-
* @
|
|
655
|
+
* @template Worker - Type of worker.
|
|
638
656
|
*/
|
|
639
657
|
type EventHandler<Worker extends IWorker> = ErrorHandler<Worker> | ExitHandler<Worker> | MessageHandler<Worker> | OnlineHandler<Worker>;
|
|
640
658
|
/**
|
|
641
659
|
* Callback invoked when the worker exits successfully.
|
|
642
|
-
* @
|
|
660
|
+
* @template Worker - Type of worker.
|
|
643
661
|
*/
|
|
644
662
|
type ExitHandler<Worker extends IWorker> = (this: Worker, exitCode: number) => void;
|
|
645
663
|
/**
|
|
646
664
|
* Callback invoked if the worker has received a message.
|
|
647
|
-
* @
|
|
665
|
+
* @template Worker - Type of worker.
|
|
648
666
|
*/
|
|
649
667
|
type MessageHandler<Worker extends IWorker> = (this: Worker, message: unknown) => void;
|
|
650
668
|
/**
|
|
651
669
|
* Callback invoked when the worker has started successfully.
|
|
652
|
-
* @
|
|
670
|
+
* @template Worker - Type of worker.
|
|
653
671
|
*/
|
|
654
672
|
type OnlineHandler<Worker extends IWorker> = (this: Worker) => void;
|
|
655
673
|
/**
|
|
@@ -779,8 +797,8 @@ interface IWorker extends EventEmitter {
|
|
|
779
797
|
}
|
|
780
798
|
/**
|
|
781
799
|
* Worker node interface.
|
|
782
|
-
* @
|
|
783
|
-
* @
|
|
800
|
+
* @template Worker - Type of worker.
|
|
801
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
784
802
|
* @internal
|
|
785
803
|
*/
|
|
786
804
|
interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitter {
|
|
@@ -807,7 +825,8 @@ interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitt
|
|
|
807
825
|
readonly dequeueLastPrioritizedTask: () => Task<Data> | undefined;
|
|
808
826
|
/**
|
|
809
827
|
* Dequeue task.
|
|
810
|
-
* @param bucket - The prioritized bucket to dequeue from.
|
|
828
|
+
* @param bucket - The prioritized bucket to dequeue from.
|
|
829
|
+
* @defaultValue 0
|
|
811
830
|
* @returns The dequeued task.
|
|
812
831
|
*/
|
|
813
832
|
readonly dequeueTask: (bucket?: number) => Task<Data> | undefined;
|
|
@@ -1019,9 +1038,9 @@ declare const PoolEvents: Readonly<{
|
|
|
1019
1038
|
}>;
|
|
1020
1039
|
/**
|
|
1021
1040
|
* Contract definition for a poolifier pool.
|
|
1022
|
-
* @
|
|
1023
|
-
* @
|
|
1024
|
-
* @
|
|
1041
|
+
* @template Worker - Type of worker which manages this pool.
|
|
1042
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1043
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
1025
1044
|
*/
|
|
1026
1045
|
interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
1027
1046
|
/**
|
|
@@ -1030,8 +1049,8 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
|
1030
1049
|
* @param name - The name of the task function.
|
|
1031
1050
|
* @param fn - The task function.
|
|
1032
1051
|
* @returns `true` if the task function was added, `false` otherwise.
|
|
1033
|
-
* @throws {
|
|
1034
|
-
* @throws {
|
|
1052
|
+
* @throws {TypeError} If the `name` parameter is not a string or an empty string.
|
|
1053
|
+
* @throws {TypeError} If the `fn` parameter is not a function or task function object.
|
|
1035
1054
|
*/
|
|
1036
1055
|
readonly addTaskFunction: (name: string, fn: TaskFunction<Data, Response> | TaskFunctionObject<Data, Response>) => Promise<boolean>;
|
|
1037
1056
|
/**
|
|
@@ -1206,7 +1225,7 @@ interface PoolInfo {
|
|
|
1206
1225
|
}
|
|
1207
1226
|
/**
|
|
1208
1227
|
* Options for a poolifier pool.
|
|
1209
|
-
* @
|
|
1228
|
+
* @template Worker - Type of worker.
|
|
1210
1229
|
*/
|
|
1211
1230
|
interface PoolOptions<Worker extends IWorker> {
|
|
1212
1231
|
/**
|
|
@@ -1264,7 +1283,7 @@ interface PoolOptions<Worker extends IWorker> {
|
|
|
1264
1283
|
tasksQueueOptions?: TasksQueueOptions;
|
|
1265
1284
|
/**
|
|
1266
1285
|
* The default worker choice strategy to use in this pool.
|
|
1267
|
-
* @defaultValue WorkerChoiceStrategies.
|
|
1286
|
+
* @defaultValue WorkerChoiceStrategies.LEAST_USED
|
|
1268
1287
|
*/
|
|
1269
1288
|
workerChoiceStrategy?: WorkerChoiceStrategy;
|
|
1270
1289
|
/**
|
|
@@ -1315,9 +1334,9 @@ interface TasksQueueOptions {
|
|
|
1315
1334
|
|
|
1316
1335
|
/**
|
|
1317
1336
|
* The worker choice strategies context.
|
|
1318
|
-
* @
|
|
1319
|
-
* @
|
|
1320
|
-
* @
|
|
1337
|
+
* @template Worker - Type of worker.
|
|
1338
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1339
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
1321
1340
|
* @internal
|
|
1322
1341
|
*/
|
|
1323
1342
|
declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
@@ -1345,17 +1364,19 @@ declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unkno
|
|
|
1345
1364
|
/**
|
|
1346
1365
|
* Worker choice strategies context constructor.
|
|
1347
1366
|
* @param pool - The pool instance.
|
|
1348
|
-
* @param workerChoiceStrategies - The worker choice strategies.
|
|
1367
|
+
* @param workerChoiceStrategies - The worker choice strategies.
|
|
1368
|
+
* @defaultValue [WorkerChoiceStrategies.LEAST_USED]
|
|
1349
1369
|
* @param opts - The worker choice strategy options.
|
|
1350
1370
|
*/
|
|
1351
1371
|
constructor(pool: IPool<Worker, Data, Response>, workerChoiceStrategies?: WorkerChoiceStrategy[], opts?: WorkerChoiceStrategyOptions);
|
|
1352
1372
|
/**
|
|
1353
|
-
* Executes the given worker choice strategy
|
|
1354
|
-
* @param workerChoiceStrategy - The worker choice strategy
|
|
1373
|
+
* Executes the given worker choice strategy.
|
|
1374
|
+
* @param workerChoiceStrategy - The worker choice strategy.
|
|
1375
|
+
* @param workerNodeKeysSet - The worker node keys affinity set. If undefined, all workers are eligible.
|
|
1355
1376
|
* @returns The key of the worker node.
|
|
1356
|
-
* @throws {
|
|
1377
|
+
* @throws {Error} If after computed retries the worker node key is null or undefined.
|
|
1357
1378
|
*/
|
|
1358
|
-
execute(workerChoiceStrategy?: WorkerChoiceStrategy): number;
|
|
1379
|
+
execute(workerChoiceStrategy?: WorkerChoiceStrategy, workerNodeKeysSet?: ReadonlySet<number>): number;
|
|
1359
1380
|
/**
|
|
1360
1381
|
* Gets the active worker choice strategies in the context policy.
|
|
1361
1382
|
* @returns The strategies policy.
|
|
@@ -1409,10 +1430,11 @@ declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unkno
|
|
|
1409
1430
|
*/
|
|
1410
1431
|
private addWorkerChoiceStrategy;
|
|
1411
1432
|
/**
|
|
1412
|
-
* Executes the given worker choice strategy.
|
|
1413
|
-
* @param workerChoiceStrategy - The worker choice strategy.
|
|
1433
|
+
* Executes the given worker choice strategy in the context algorithm.
|
|
1434
|
+
* @param workerChoiceStrategy - The worker choice strategy algorithm to execute.
|
|
1435
|
+
* @param workerNodeKeysSet - The worker node keys affinity set. If undefined, all workers are eligible.
|
|
1414
1436
|
* @returns The key of the worker node.
|
|
1415
|
-
* @throws {
|
|
1437
|
+
* @throws {Error} If after computed retries the worker node key is null or undefined.
|
|
1416
1438
|
*/
|
|
1417
1439
|
private executeStrategy;
|
|
1418
1440
|
/**
|
|
@@ -1425,9 +1447,9 @@ declare class WorkerChoiceStrategiesContext<Worker extends IWorker, Data = unkno
|
|
|
1425
1447
|
|
|
1426
1448
|
/**
|
|
1427
1449
|
* Base class that implements some shared logic for all poolifier pools.
|
|
1428
|
-
* @
|
|
1429
|
-
* @
|
|
1430
|
-
* @
|
|
1450
|
+
* @template Worker - Type of worker which manages this pool.
|
|
1451
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1452
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
1431
1453
|
*/
|
|
1432
1454
|
declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Response = unknown> implements IPool<Worker, Data, Response> {
|
|
1433
1455
|
protected readonly minimumNumberOfWorkers: number;
|
|
@@ -1670,7 +1692,7 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1670
1692
|
* Adds the given worker node in the pool worker nodes.
|
|
1671
1693
|
* @param workerNode - The worker node.
|
|
1672
1694
|
* @returns The added worker node key.
|
|
1673
|
-
* @throws {
|
|
1695
|
+
* @throws {Error} If the added worker node is not found.
|
|
1674
1696
|
*/
|
|
1675
1697
|
private addWorkerNode;
|
|
1676
1698
|
private buildTasksQueueOptions;
|
|
@@ -1683,7 +1705,7 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1683
1705
|
/**
|
|
1684
1706
|
* Checks if the worker id sent in the received message from a worker is valid.
|
|
1685
1707
|
* @param message - The received message.
|
|
1686
|
-
* @throws {
|
|
1708
|
+
* @throws {Error} If the worker id is invalid.
|
|
1687
1709
|
*/
|
|
1688
1710
|
private checkMessageWorkerId;
|
|
1689
1711
|
private checkMinimumNumberOfWorkers;
|
|
@@ -1719,6 +1741,12 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1719
1741
|
* @returns The task function worker choice strategy if the task function worker choice strategy is defined, `undefined` otherwise.
|
|
1720
1742
|
*/
|
|
1721
1743
|
private readonly getTaskFunctionWorkerChoiceStrategy;
|
|
1744
|
+
/**
|
|
1745
|
+
* Gets task function worker node keys affinity set, if any.
|
|
1746
|
+
* @param name - The task function name.
|
|
1747
|
+
* @returns The task function worker node keys affinity set, or `undefined` if not defined.
|
|
1748
|
+
*/
|
|
1749
|
+
private readonly getTaskFunctionWorkerNodeKeysSet;
|
|
1722
1750
|
private getTasksQueuePriority;
|
|
1723
1751
|
/**
|
|
1724
1752
|
* Gets the worker choice strategies registered in this pool.
|
|
@@ -1791,7 +1819,8 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1791
1819
|
private shallUpdateTaskFunctionWorkerUsage;
|
|
1792
1820
|
/**
|
|
1793
1821
|
* Starts the minimum number of workers.
|
|
1794
|
-
* @param initWorkerNodeUsage - Whether to initialize the worker node usage or not.
|
|
1822
|
+
* @param initWorkerNodeUsage - Whether to initialize the worker node usage or not.
|
|
1823
|
+
* @defaultValue false
|
|
1795
1824
|
*/
|
|
1796
1825
|
private startMinimumNumberOfWorkers;
|
|
1797
1826
|
private readonly stealTask;
|
|
@@ -1809,8 +1838,8 @@ declare abstract class AbstractPool<Worker extends IWorker, Data = unknown, Resp
|
|
|
1809
1838
|
type ClusterPoolOptions = PoolOptions<Worker>;
|
|
1810
1839
|
/**
|
|
1811
1840
|
* A cluster pool with a fixed number of workers.
|
|
1812
|
-
* @
|
|
1813
|
-
* @
|
|
1841
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1842
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
1814
1843
|
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
|
|
1815
1844
|
* @since 2.0.0
|
|
1816
1845
|
*/
|
|
@@ -1858,8 +1887,8 @@ declare class FixedClusterPool<Data = unknown, Response = unknown> extends Abstr
|
|
|
1858
1887
|
*
|
|
1859
1888
|
* This cluster pool creates new workers when the others are busy, up to the maximum number of workers.
|
|
1860
1889
|
* 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`.
|
|
1861
|
-
* @
|
|
1862
|
-
* @
|
|
1890
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1891
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
1863
1892
|
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
|
|
1864
1893
|
* @since 2.0.0
|
|
1865
1894
|
*/
|
|
@@ -1910,8 +1939,8 @@ declare class DynamicClusterPool<Data = unknown, Response = unknown> extends Fix
|
|
|
1910
1939
|
type ThreadPoolOptions = PoolOptions<Worker$1>;
|
|
1911
1940
|
/**
|
|
1912
1941
|
* A thread pool with a fixed number of threads.
|
|
1913
|
-
* @
|
|
1914
|
-
* @
|
|
1942
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1943
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
1915
1944
|
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
|
|
1916
1945
|
* @since 0.0.1
|
|
1917
1946
|
*/
|
|
@@ -1957,8 +1986,8 @@ declare class FixedThreadPool<Data = unknown, Response = unknown> extends Abstra
|
|
|
1957
1986
|
*
|
|
1958
1987
|
* This thread pool creates new threads when the others are busy, up to the maximum number of threads.
|
|
1959
1988
|
* 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`.
|
|
1960
|
-
* @
|
|
1961
|
-
* @
|
|
1989
|
+
* @template Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
1990
|
+
* @template Response - Type of execution response. This can only be structured-cloneable data.
|
|
1962
1991
|
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
|
|
1963
1992
|
* @since 0.0.1
|
|
1964
1993
|
*/
|
|
@@ -2005,7 +2034,7 @@ declare class DynamicThreadPool<Data = unknown, Response = unknown> extends Fixe
|
|
|
2005
2034
|
|
|
2006
2035
|
/**
|
|
2007
2036
|
* Fixed queue node.
|
|
2008
|
-
* @
|
|
2037
|
+
* @template T - Type of fixed queue node data.
|
|
2009
2038
|
* @internal
|
|
2010
2039
|
*/
|
|
2011
2040
|
interface FixedQueueNode<T> {
|
|
@@ -2015,7 +2044,7 @@ interface FixedQueueNode<T> {
|
|
|
2015
2044
|
}
|
|
2016
2045
|
/**
|
|
2017
2046
|
* Fixed queue.
|
|
2018
|
-
* @
|
|
2047
|
+
* @template T - Type of fixed queue data.
|
|
2019
2048
|
* @internal
|
|
2020
2049
|
*/
|
|
2021
2050
|
interface IFixedQueue<T> {
|
|
@@ -2052,7 +2081,7 @@ interface IFixedQueue<T> {
|
|
|
2052
2081
|
* @param data - Data to enqueue.
|
|
2053
2082
|
* @param priority - Priority of the data. Lower values have higher priority.
|
|
2054
2083
|
* @returns The new size of the fixed queue.
|
|
2055
|
-
* @throws If the fixed queue is full.
|
|
2084
|
+
* @throws {Error} If the fixed queue is full.
|
|
2056
2085
|
*/
|
|
2057
2086
|
enqueue: (data: T, priority?: number) => number;
|
|
2058
2087
|
/**
|
|
@@ -2081,9 +2110,9 @@ declare const availableParallelism: () => number;
|
|
|
2081
2110
|
|
|
2082
2111
|
/**
|
|
2083
2112
|
* Base class that implements some shared logic for all poolifier workers.
|
|
2084
|
-
* @
|
|
2085
|
-
* @
|
|
2086
|
-
* @
|
|
2113
|
+
* @template MainWorker - Type of main worker.
|
|
2114
|
+
* @template Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
|
|
2115
|
+
* @template Response - Type of response the worker sends back to the main worker. This can only be structured-cloneable data.
|
|
2087
2116
|
*/
|
|
2088
2117
|
declare abstract class AbstractWorker<MainWorker extends MessagePort | Worker, Data = unknown, Response = unknown> {
|
|
2089
2118
|
protected readonly isMain: boolean | undefined;
|
|
@@ -2155,7 +2184,7 @@ declare abstract class AbstractWorker<MainWorker extends MessagePort | Worker, D
|
|
|
2155
2184
|
/**
|
|
2156
2185
|
* Returns the main worker.
|
|
2157
2186
|
* @returns Reference to the main worker.
|
|
2158
|
-
* @throws {
|
|
2187
|
+
* @throws {Error} If the main worker is not set.
|
|
2159
2188
|
*/
|
|
2160
2189
|
protected getMainWorker(): MainWorker;
|
|
2161
2190
|
/**
|
|
@@ -2219,7 +2248,7 @@ declare abstract class AbstractWorker<MainWorker extends MessagePort | Worker, D
|
|
|
2219
2248
|
/**
|
|
2220
2249
|
* Check if the message worker id is set and matches the worker id.
|
|
2221
2250
|
* @param message - The message to check.
|
|
2222
|
-
* @throws {
|
|
2251
|
+
* @throws {Error} If the message worker id is not set or does not match the worker id.
|
|
2223
2252
|
*/
|
|
2224
2253
|
private checkMessageWorkerId;
|
|
2225
2254
|
/**
|
|
@@ -2256,8 +2285,8 @@ declare abstract class AbstractWorker<MainWorker extends MessagePort | Worker, D
|
|
|
2256
2285
|
*
|
|
2257
2286
|
* If you use a `DynamicClusterPool` the extra workers that were created will be terminated,
|
|
2258
2287
|
* but the minimum number of workers will be guaranteed.
|
|
2259
|
-
* @
|
|
2260
|
-
* @
|
|
2288
|
+
* @template Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
|
|
2289
|
+
* @template Response - Type of response the worker sends back to the main worker. This can only be structured-cloneable data.
|
|
2261
2290
|
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
|
|
2262
2291
|
* @since 2.0.0
|
|
2263
2292
|
*/
|
|
@@ -2292,8 +2321,8 @@ declare class ClusterWorker<Data = unknown, Response = unknown> extends Abstract
|
|
|
2292
2321
|
*
|
|
2293
2322
|
* If you use a `DynamicThreadPool` the extra workers that were created will be terminated,
|
|
2294
2323
|
* but the minimum number of workers will be guaranteed.
|
|
2295
|
-
* @
|
|
2296
|
-
* @
|
|
2324
|
+
* @template Data - Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
|
|
2325
|
+
* @template Response - Type of response the worker sends back to the main thread. This can only be structured-cloneable data.
|
|
2297
2326
|
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
|
|
2298
2327
|
* @since 0.0.1
|
|
2299
2328
|
*/
|