poolifier 3.1.21 → 3.1.22

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
@@ -1,10 +1,116 @@
1
1
  /// <reference types="node" />
2
- import { TransferListItem, MessagePort, WorkerOptions as WorkerOptions$1, MessageChannel, Worker as Worker$1 } from 'node:worker_threads';
3
2
  import { EventEmitter, EventEmitterAsyncResource } from 'node:events';
4
- import { EventLoopUtilization } from 'node:perf_hooks';
3
+ import { TransferListItem, MessagePort, WorkerOptions as WorkerOptions$1, MessageChannel, Worker as Worker$1 } from 'node:worker_threads';
5
4
  import { AsyncResource } from 'node:async_hooks';
5
+ import { EventLoopUtilization } from 'node:perf_hooks';
6
6
  import { ClusterSettings, Worker } from 'node:cluster';
7
7
 
8
+ /**
9
+ * Array with a maximum length and shifting items when full.
10
+ *
11
+ * @typeParam T - Type of items.
12
+ * @internal
13
+ */
14
+ declare class CircularArray<T> extends Array<T> {
15
+ size: number;
16
+ constructor(size?: number, ...items: T[]);
17
+ /** @inheritDoc */
18
+ push(...items: T[]): number;
19
+ /** @inheritDoc */
20
+ unshift(...items: T[]): number;
21
+ /** @inheritDoc */
22
+ concat(...items: Array<T | ConcatArray<T>>): CircularArray<T>;
23
+ /** @inheritDoc */
24
+ splice(start: number, deleteCount?: number, ...items: T[]): CircularArray<T>;
25
+ resize(size: number): void;
26
+ empty(): boolean;
27
+ full(): boolean;
28
+ private checkSize;
29
+ }
30
+
31
+ /**
32
+ * Linked list node interface.
33
+ *
34
+ * @typeParam T - Type of linked list node data.
35
+ * @internal
36
+ */
37
+ interface ILinkedListNode<T> {
38
+ data: T;
39
+ next?: ILinkedListNode<T>;
40
+ prev?: ILinkedListNode<T>;
41
+ }
42
+ /**
43
+ * Deque.
44
+ * Implemented with a doubly linked list.
45
+ *
46
+ * @typeParam T - Type of deque data.
47
+ * @internal
48
+ */
49
+ declare class Deque<T> {
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();
57
+ /**
58
+ * Appends data to the deque.
59
+ *
60
+ * @param data - Data to append.
61
+ * @returns The new size of the deque.
62
+ */
63
+ push(data: T): number;
64
+ /**
65
+ * Prepends data to the deque.
66
+ *
67
+ * @param data - Data to prepend.
68
+ * @returns The new size of the deque.
69
+ */
70
+ unshift(data: T): number;
71
+ /**
72
+ * Pops data from the deque.
73
+ *
74
+ * @returns The popped data or `undefined` if the deque is empty.
75
+ */
76
+ pop(): T | undefined;
77
+ /**
78
+ * Shifts data from the deque.
79
+ *
80
+ * @returns The shifted data or `undefined` if the deque is empty.
81
+ */
82
+ shift(): T | undefined;
83
+ /**
84
+ * Peeks at the first data.
85
+ * @returns The first data or `undefined` if the deque is empty.
86
+ */
87
+ peekFirst(): T | undefined;
88
+ /**
89
+ * Peeks at the last data.
90
+ * @returns The last data or `undefined` if the deque is empty.
91
+ */
92
+ peekLast(): T | undefined;
93
+ /**
94
+ * Clears the deque.
95
+ */
96
+ clear(): void;
97
+ /**
98
+ * Returns an iterator for the deque.
99
+ *
100
+ * @returns An iterator for the deque.
101
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
102
+ */
103
+ [Symbol.iterator](): Iterator<T>;
104
+ /**
105
+ * Returns an backward iterator for the deque.
106
+ *
107
+ * @returns An backward iterator for the deque.
108
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
109
+ */
110
+ backward(): Iterable<T>;
111
+ private incrementSize;
112
+ }
113
+
8
114
  /**
9
115
  * Enumeration of kill behaviors.
10
116
  */
@@ -285,26 +391,200 @@ interface TaskFunctionOperationResult {
285
391
  }
286
392
 
287
393
  /**
288
- * Array with a maximum length and shifting items when full.
394
+ * Enumeration of worker choice strategies.
395
+ */
396
+ declare const WorkerChoiceStrategies: Readonly<{
397
+ /**
398
+ * Round robin worker selection strategy.
399
+ */
400
+ readonly ROUND_ROBIN: "ROUND_ROBIN";
401
+ /**
402
+ * Least used worker selection strategy.
403
+ */
404
+ readonly LEAST_USED: "LEAST_USED";
405
+ /**
406
+ * Least busy worker selection strategy.
407
+ */
408
+ readonly LEAST_BUSY: "LEAST_BUSY";
409
+ /**
410
+ * Least ELU worker selection strategy.
411
+ */
412
+ readonly LEAST_ELU: "LEAST_ELU";
413
+ /**
414
+ * Fair share worker selection strategy.
415
+ */
416
+ readonly FAIR_SHARE: "FAIR_SHARE";
417
+ /**
418
+ * Weighted round robin worker selection strategy.
419
+ */
420
+ readonly WEIGHTED_ROUND_ROBIN: "WEIGHTED_ROUND_ROBIN";
421
+ /**
422
+ * Interleaved weighted round robin worker selection strategy.
423
+ *
424
+ * @experimental
425
+ */
426
+ readonly INTERLEAVED_WEIGHTED_ROUND_ROBIN: "INTERLEAVED_WEIGHTED_ROUND_ROBIN";
427
+ }>;
428
+ /**
429
+ * Worker choice strategy.
430
+ */
431
+ type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies;
432
+ /**
433
+ * Enumeration of measurements.
434
+ */
435
+ declare const Measurements: Readonly<{
436
+ readonly runTime: "runTime";
437
+ readonly waitTime: "waitTime";
438
+ readonly elu: "elu";
439
+ }>;
440
+ /**
441
+ * Measurement.
442
+ */
443
+ type Measurement = keyof typeof Measurements;
444
+ /**
445
+ * Measurement options.
446
+ */
447
+ interface MeasurementOptions {
448
+ /**
449
+ * Set measurement median.
450
+ */
451
+ readonly median: boolean;
452
+ }
453
+ /**
454
+ * Worker choice strategy options.
455
+ */
456
+ interface WorkerChoiceStrategyOptions {
457
+ /**
458
+ * Measurement to use in worker choice strategy supporting it.
459
+ */
460
+ readonly measurement?: Measurement;
461
+ /**
462
+ * Runtime options.
463
+ *
464
+ * @defaultValue \{ median: false \}
465
+ */
466
+ readonly runTime?: MeasurementOptions;
467
+ /**
468
+ * Wait time options.
469
+ *
470
+ * @defaultValue \{ median: false \}
471
+ */
472
+ readonly waitTime?: MeasurementOptions;
473
+ /**
474
+ * Event loop utilization options.
475
+ *
476
+ * @defaultValue \{ median: false \}
477
+ */
478
+ readonly elu?: MeasurementOptions;
479
+ /**
480
+ * Worker weights to use for weighted round robin worker selection strategies.
481
+ * A weight is tasks maximum execution time in milliseconds for a worker node.
482
+ *
483
+ * @defaultValue Weights computed automatically given the CPU performance.
484
+ */
485
+ weights?: Record<number, number>;
486
+ }
487
+ /**
488
+ * Measurement statistics requirements.
289
489
  *
290
- * @typeParam T - Type of items.
291
490
  * @internal
292
491
  */
293
- declare class CircularArray<T> extends Array<T> {
294
- size: number;
295
- constructor(size?: number, ...items: T[]);
296
- /** @inheritDoc */
297
- push(...items: T[]): number;
298
- /** @inheritDoc */
299
- unshift(...items: T[]): number;
300
- /** @inheritDoc */
301
- concat(...items: Array<T | ConcatArray<T>>): CircularArray<T>;
302
- /** @inheritDoc */
303
- splice(start: number, deleteCount?: number, ...items: T[]): CircularArray<T>;
304
- resize(size: number): void;
305
- empty(): boolean;
306
- full(): boolean;
307
- private checkSize;
492
+ interface MeasurementStatisticsRequirements {
493
+ /**
494
+ * Requires measurement aggregate.
495
+ */
496
+ aggregate: boolean;
497
+ /**
498
+ * Requires measurement average.
499
+ */
500
+ average: boolean;
501
+ /**
502
+ * Requires measurement median.
503
+ */
504
+ median: boolean;
505
+ }
506
+ /**
507
+ * Pool worker node worker usage statistics requirements.
508
+ *
509
+ * @internal
510
+ */
511
+ interface TaskStatisticsRequirements {
512
+ /**
513
+ * Tasks runtime requirements.
514
+ */
515
+ readonly runTime: MeasurementStatisticsRequirements;
516
+ /**
517
+ * Tasks wait time requirements.
518
+ */
519
+ readonly waitTime: MeasurementStatisticsRequirements;
520
+ /**
521
+ * Tasks event loop utilization requirements.
522
+ */
523
+ readonly elu: MeasurementStatisticsRequirements;
524
+ }
525
+ /**
526
+ * Strategy policy.
527
+ *
528
+ * @internal
529
+ */
530
+ interface StrategyPolicy {
531
+ /**
532
+ * Expects tasks execution on the newly created dynamic worker.
533
+ */
534
+ readonly dynamicWorkerUsage: boolean;
535
+ /**
536
+ * Expects the newly created dynamic worker to be flagged as ready.
537
+ */
538
+ readonly dynamicWorkerReady: boolean;
539
+ }
540
+ /**
541
+ * Worker choice strategy interface.
542
+ *
543
+ * @internal
544
+ */
545
+ interface IWorkerChoiceStrategy {
546
+ /**
547
+ * Strategy policy.
548
+ */
549
+ readonly strategyPolicy: StrategyPolicy;
550
+ /**
551
+ * Tasks statistics requirements.
552
+ */
553
+ readonly taskStatisticsRequirements: TaskStatisticsRequirements;
554
+ /**
555
+ * Resets strategy internals.
556
+ *
557
+ * @returns `true` if the reset is successful, `false` otherwise.
558
+ */
559
+ readonly reset: () => boolean;
560
+ /**
561
+ * Updates the worker node key strategy internals.
562
+ * This is called after a task has been executed on a worker node.
563
+ *
564
+ * @returns `true` if the update is successful, `false` otherwise.
565
+ */
566
+ readonly update: (workerNodeKey: number) => boolean;
567
+ /**
568
+ * Chooses a worker node in the pool and returns its key.
569
+ * If no worker nodes are not eligible, `undefined` is returned.
570
+ * If `undefined` is returned, the caller retry.
571
+ *
572
+ * @returns The worker node key or `undefined`.
573
+ */
574
+ readonly choose: () => number | undefined;
575
+ /**
576
+ * Removes the worker node key from strategy internals.
577
+ *
578
+ * @param workerNodeKey - The worker node key.
579
+ * @returns `true` if the worker node key is removed, `false` otherwise.
580
+ */
581
+ readonly remove: (workerNodeKey: number) => boolean;
582
+ /**
583
+ * Sets the worker choice strategy options.
584
+ *
585
+ * @param opts - The worker choice strategy options.
586
+ */
587
+ readonly setOptions: (opts: WorkerChoiceStrategyOptions | undefined) => void;
308
588
  }
309
589
 
310
590
  /**
@@ -550,317 +830,120 @@ interface WorkerNodeOptions {
550
830
  * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
551
831
  * @internal
552
832
  */
553
- interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitter {
554
- /**
555
- * Worker.
556
- */
557
- readonly worker: Worker;
558
- /**
559
- * Worker info.
560
- */
561
- readonly info: WorkerInfo;
562
- /**
563
- * Worker usage statistics.
564
- */
565
- readonly usage: WorkerUsage;
566
- /**
567
- * Worker choice strategy data.
568
- * This is used to store data that are specific to the worker choice strategy.
569
- */
570
- strategyData?: StrategyData;
571
- /**
572
- * Message channel (worker thread only).
573
- */
574
- readonly messageChannel?: MessageChannel;
575
- /**
576
- * Tasks queue back pressure size.
577
- * This is the number of tasks that can be enqueued before the worker node has back pressure.
578
- */
579
- tasksQueueBackPressureSize: number;
580
- /**
581
- * Tasks queue size.
582
- *
583
- * @returns The tasks queue size.
584
- */
585
- readonly tasksQueueSize: () => number;
586
- /**
587
- * Enqueue task.
588
- *
589
- * @param task - The task to queue.
590
- * @returns The tasks queue size.
591
- */
592
- readonly enqueueTask: (task: Task<Data>) => number;
593
- /**
594
- * Prepends a task to the tasks queue.
595
- *
596
- * @param task - The task to prepend.
597
- * @returns The tasks queue size.
598
- */
599
- readonly unshiftTask: (task: Task<Data>) => number;
600
- /**
601
- * Dequeue task.
602
- *
603
- * @returns The dequeued task.
604
- */
605
- readonly dequeueTask: () => Task<Data> | undefined;
606
- /**
607
- * Pops a task from the tasks queue.
608
- *
609
- * @returns The popped task.
610
- */
611
- readonly popTask: () => Task<Data> | undefined;
612
- /**
613
- * Clears tasks queue.
614
- */
615
- readonly clearTasksQueue: () => void;
616
- /**
617
- * Whether the worker node has back pressure (i.e. its tasks queue is full).
618
- *
619
- * @returns `true` if the worker node has back pressure, `false` otherwise.
620
- */
621
- readonly hasBackPressure: () => boolean;
622
- /**
623
- * Resets usage statistics.
624
- */
625
- readonly resetUsage: () => void;
626
- /**
627
- * Terminates the worker node.
628
- */
629
- readonly terminate: () => Promise<void>;
630
- /**
631
- * Registers a worker event handler.
632
- *
633
- * @param event - The event.
634
- * @param handler - The event handler.
635
- */
636
- readonly registerWorkerEventHandler: (event: string, handler: EventHandler<Worker>) => void;
637
- /**
638
- * Registers once a worker event handler.
639
- *
640
- * @param event - The event.
641
- * @param handler - The event handler.
642
- */
643
- readonly registerOnceWorkerEventHandler: (event: string, handler: EventHandler<Worker>) => void;
644
- /**
645
- * Gets task function worker usage statistics.
646
- *
647
- * @param name - The task function name.
648
- * @returns The task function worker usage statistics if the task function worker usage statistics are initialized, `undefined` otherwise.
649
- */
650
- readonly getTaskFunctionWorkerUsage: (name: string) => WorkerUsage | undefined;
651
- /**
652
- * Deletes task function worker usage statistics.
653
- *
654
- * @param name - The task function name.
655
- * @returns `true` if the task function worker usage statistics were deleted, `false` otherwise.
656
- */
657
- readonly deleteTaskFunctionWorkerUsage: (name: string) => boolean;
658
- }
659
- /**
660
- * Worker node event detail.
661
- *
662
- * @internal
663
- */
664
- interface WorkerNodeEventDetail {
665
- workerId?: number;
666
- workerNodeKey?: number;
667
- }
668
-
669
- /**
670
- * Enumeration of worker choice strategies.
671
- */
672
- declare const WorkerChoiceStrategies: Readonly<{
673
- /**
674
- * Round robin worker selection strategy.
675
- */
676
- readonly ROUND_ROBIN: "ROUND_ROBIN";
677
- /**
678
- * Least used worker selection strategy.
679
- */
680
- readonly LEAST_USED: "LEAST_USED";
681
- /**
682
- * Least busy worker selection strategy.
683
- */
684
- readonly LEAST_BUSY: "LEAST_BUSY";
685
- /**
686
- * Least ELU worker selection strategy.
687
- */
688
- readonly LEAST_ELU: "LEAST_ELU";
689
- /**
690
- * Fair share worker selection strategy.
691
- */
692
- readonly FAIR_SHARE: "FAIR_SHARE";
693
- /**
694
- * Weighted round robin worker selection strategy.
695
- */
696
- readonly WEIGHTED_ROUND_ROBIN: "WEIGHTED_ROUND_ROBIN";
697
- /**
698
- * Interleaved weighted round robin worker selection strategy.
699
- *
700
- * @experimental
701
- */
702
- readonly INTERLEAVED_WEIGHTED_ROUND_ROBIN: "INTERLEAVED_WEIGHTED_ROUND_ROBIN";
703
- }>;
704
- /**
705
- * Worker choice strategy.
706
- */
707
- type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies;
708
- /**
709
- * Enumeration of measurements.
710
- */
711
- declare const Measurements: Readonly<{
712
- readonly runTime: "runTime";
713
- readonly waitTime: "waitTime";
714
- readonly elu: "elu";
715
- }>;
716
- /**
717
- * Measurement.
718
- */
719
- type Measurement = keyof typeof Measurements;
720
- /**
721
- * Measurement options.
722
- */
723
- interface MeasurementOptions {
724
- /**
725
- * Set measurement median.
726
- */
727
- readonly median: boolean;
728
- }
729
- /**
730
- * Worker choice strategy options.
731
- */
732
- interface WorkerChoiceStrategyOptions {
733
- /**
734
- * Measurement to use in worker choice strategy supporting it.
735
- */
736
- readonly measurement?: Measurement;
833
+ interface IWorkerNode<Worker extends IWorker, Data = unknown> extends EventEmitter {
737
834
  /**
738
- * Runtime options.
739
- *
740
- * @defaultValue \{ median: false \}
835
+ * Worker.
741
836
  */
742
- readonly runTime?: MeasurementOptions;
837
+ readonly worker: Worker;
743
838
  /**
744
- * Wait time options.
745
- *
746
- * @defaultValue \{ median: false \}
839
+ * Worker info.
747
840
  */
748
- readonly waitTime?: MeasurementOptions;
841
+ readonly info: WorkerInfo;
749
842
  /**
750
- * Event loop utilization options.
751
- *
752
- * @defaultValue \{ median: false \}
843
+ * Worker usage statistics.
753
844
  */
754
- readonly elu?: MeasurementOptions;
845
+ readonly usage: WorkerUsage;
755
846
  /**
756
- * Worker weights to use for weighted round robin worker selection strategies.
757
- * A weight is tasks maximum execution time in milliseconds for a worker node.
758
- *
759
- * @defaultValue Weights computed automatically given the CPU performance.
847
+ * Worker choice strategy data.
848
+ * This is used to store data that are specific to the worker choice strategy.
760
849
  */
761
- weights?: Record<number, number>;
762
- }
763
- /**
764
- * Measurement statistics requirements.
765
- *
766
- * @internal
767
- */
768
- interface MeasurementStatisticsRequirements {
850
+ strategyData?: StrategyData;
769
851
  /**
770
- * Requires measurement aggregate.
852
+ * Message channel (worker thread only).
771
853
  */
772
- aggregate: boolean;
854
+ readonly messageChannel?: MessageChannel;
773
855
  /**
774
- * Requires measurement average.
856
+ * Tasks queue back pressure size.
857
+ * This is the number of tasks that can be enqueued before the worker node has back pressure.
775
858
  */
776
- average: boolean;
859
+ tasksQueueBackPressureSize: number;
777
860
  /**
778
- * Requires measurement median.
861
+ * Tasks queue size.
862
+ *
863
+ * @returns The tasks queue size.
779
864
  */
780
- median: boolean;
781
- }
782
- /**
783
- * Pool worker node worker usage statistics requirements.
784
- *
785
- * @internal
786
- */
787
- interface TaskStatisticsRequirements {
865
+ readonly tasksQueueSize: () => number;
788
866
  /**
789
- * Tasks runtime requirements.
867
+ * Enqueue task.
868
+ *
869
+ * @param task - The task to queue.
870
+ * @returns The tasks queue size.
790
871
  */
791
- readonly runTime: MeasurementStatisticsRequirements;
872
+ readonly enqueueTask: (task: Task<Data>) => number;
792
873
  /**
793
- * Tasks wait time requirements.
874
+ * Prepends a task to the tasks queue.
875
+ *
876
+ * @param task - The task to prepend.
877
+ * @returns The tasks queue size.
794
878
  */
795
- readonly waitTime: MeasurementStatisticsRequirements;
879
+ readonly unshiftTask: (task: Task<Data>) => number;
796
880
  /**
797
- * Tasks event loop utilization requirements.
881
+ * Dequeue task.
882
+ *
883
+ * @returns The dequeued task.
798
884
  */
799
- readonly elu: MeasurementStatisticsRequirements;
800
- }
801
- /**
802
- * Strategy policy.
803
- *
804
- * @internal
805
- */
806
- interface StrategyPolicy {
885
+ readonly dequeueTask: () => Task<Data> | undefined;
807
886
  /**
808
- * Expects tasks execution on the newly created dynamic worker.
887
+ * Pops a task from the tasks queue.
888
+ *
889
+ * @returns The popped task.
809
890
  */
810
- readonly dynamicWorkerUsage: boolean;
891
+ readonly popTask: () => Task<Data> | undefined;
811
892
  /**
812
- * Expects the newly created dynamic worker to be flagged as ready.
893
+ * Clears tasks queue.
813
894
  */
814
- readonly dynamicWorkerReady: boolean;
815
- }
816
- /**
817
- * Worker choice strategy interface.
818
- *
819
- * @internal
820
- */
821
- interface IWorkerChoiceStrategy {
895
+ readonly clearTasksQueue: () => void;
822
896
  /**
823
- * Strategy policy.
897
+ * Whether the worker node has back pressure (i.e. its tasks queue is full).
898
+ *
899
+ * @returns `true` if the worker node has back pressure, `false` otherwise.
824
900
  */
825
- readonly strategyPolicy: StrategyPolicy;
901
+ readonly hasBackPressure: () => boolean;
826
902
  /**
827
- * Tasks statistics requirements.
903
+ * Resets usage statistics.
828
904
  */
829
- readonly taskStatisticsRequirements: TaskStatisticsRequirements;
905
+ readonly resetUsage: () => void;
830
906
  /**
831
- * Resets strategy internals.
832
- *
833
- * @returns `true` if the reset is successful, `false` otherwise.
907
+ * Terminates the worker node.
834
908
  */
835
- readonly reset: () => boolean;
909
+ readonly terminate: () => Promise<void>;
836
910
  /**
837
- * Updates the worker node key strategy internals.
838
- * This is called after a task has been executed on a worker node.
911
+ * Registers a worker event handler.
839
912
  *
840
- * @returns `true` if the update is successful, `false` otherwise.
913
+ * @param event - The event.
914
+ * @param handler - The event handler.
841
915
  */
842
- readonly update: (workerNodeKey: number) => boolean;
916
+ readonly registerWorkerEventHandler: (event: string, handler: EventHandler<Worker>) => void;
843
917
  /**
844
- * Chooses a worker node in the pool and returns its key.
845
- * If no worker nodes are not eligible, `undefined` is returned.
846
- * If `undefined` is returned, the caller retry.
918
+ * Registers once a worker event handler.
847
919
  *
848
- * @returns The worker node key or `undefined`.
920
+ * @param event - The event.
921
+ * @param handler - The event handler.
849
922
  */
850
- readonly choose: () => number | undefined;
923
+ readonly registerOnceWorkerEventHandler: (event: string, handler: EventHandler<Worker>) => void;
851
924
  /**
852
- * Removes the worker node key from strategy internals.
925
+ * Gets task function worker usage statistics.
853
926
  *
854
- * @param workerNodeKey - The worker node key.
855
- * @returns `true` if the worker node key is removed, `false` otherwise.
927
+ * @param name - The task function name.
928
+ * @returns The task function worker usage statistics if the task function worker usage statistics are initialized, `undefined` otherwise.
856
929
  */
857
- readonly remove: (workerNodeKey: number) => boolean;
930
+ readonly getTaskFunctionWorkerUsage: (name: string) => WorkerUsage | undefined;
858
931
  /**
859
- * Sets the worker choice strategy options.
932
+ * Deletes task function worker usage statistics.
860
933
  *
861
- * @param opts - The worker choice strategy options.
934
+ * @param name - The task function name.
935
+ * @returns `true` if the task function worker usage statistics were deleted, `false` otherwise.
862
936
  */
863
- readonly setOptions: (opts: WorkerChoiceStrategyOptions | undefined) => void;
937
+ readonly deleteTaskFunctionWorkerUsage: (name: string) => boolean;
938
+ }
939
+ /**
940
+ * Worker node event detail.
941
+ *
942
+ * @internal
943
+ */
944
+ interface WorkerNodeEventDetail {
945
+ workerId?: number;
946
+ workerNodeKey?: number;
864
947
  }
865
948
 
866
949
  /**
@@ -1079,7 +1162,7 @@ interface IPool<Worker extends IWorker, Data = unknown, Response = unknown> {
1079
1162
  */
1080
1163
  readonly workerNodes: Array<IWorkerNode<Worker, Data>>;
1081
1164
  /**
1082
- * Event emitter integrated with async resource on which events can be listened to.
1165
+ * Pool event emitter integrated with async resource.
1083
1166
  * The async tracking tooling identifier is `poolifier:<PoolType>-<WorkerType>-pool`.
1084
1167
  *
1085
1168
  * Events that can currently be listened to:
@@ -1758,6 +1841,14 @@ declare class DynamicThreadPool<Data = unknown, Response = unknown> extends Fixe
1758
1841
  protected get busy(): boolean;
1759
1842
  }
1760
1843
 
1844
+ /**
1845
+ * Returns safe host OS optimized estimate of the default amount of parallelism a pool should use.
1846
+ * Always returns a value greater than zero.
1847
+ *
1848
+ * @returns The host OS optimized maximum pool size.
1849
+ */
1850
+ declare const availableParallelism: () => number;
1851
+
1761
1852
  /**
1762
1853
  * Base class that implements some shared logic for all poolifier workers.
1763
1854
  *
@@ -1999,95 +2090,4 @@ declare class ThreadWorker<Data = unknown, Response = unknown> extends AbstractW
1999
2090
  protected handleError(error: Error | string): string;
2000
2091
  }
2001
2092
 
2002
- /**
2003
- * Linked list node interface.
2004
- *
2005
- * @typeParam T - Type of linked list node data.
2006
- * @internal
2007
- */
2008
- interface ILinkedListNode<T> {
2009
- data: T;
2010
- next?: ILinkedListNode<T>;
2011
- prev?: ILinkedListNode<T>;
2012
- }
2013
- /**
2014
- * Deque.
2015
- * Implemented with a doubly linked list.
2016
- *
2017
- * @typeParam T - Type of deque data.
2018
- * @internal
2019
- */
2020
- declare class Deque<T> {
2021
- private head?;
2022
- private tail?;
2023
- /** The size of the deque. */
2024
- size: number;
2025
- /** The maximum size of the deque. */
2026
- maxSize: number;
2027
- constructor();
2028
- /**
2029
- * Appends data to the deque.
2030
- *
2031
- * @param data - Data to append.
2032
- * @returns The new size of the deque.
2033
- */
2034
- push(data: T): number;
2035
- /**
2036
- * Prepends data to the deque.
2037
- *
2038
- * @param data - Data to prepend.
2039
- * @returns The new size of the deque.
2040
- */
2041
- unshift(data: T): number;
2042
- /**
2043
- * Pops data from the deque.
2044
- *
2045
- * @returns The popped data or `undefined` if the deque is empty.
2046
- */
2047
- pop(): T | undefined;
2048
- /**
2049
- * Shifts data from the deque.
2050
- *
2051
- * @returns The shifted data or `undefined` if the deque is empty.
2052
- */
2053
- shift(): T | undefined;
2054
- /**
2055
- * Peeks at the first data.
2056
- * @returns The first data or `undefined` if the deque is empty.
2057
- */
2058
- peekFirst(): T | undefined;
2059
- /**
2060
- * Peeks at the last data.
2061
- * @returns The last data or `undefined` if the deque is empty.
2062
- */
2063
- peekLast(): T | undefined;
2064
- /**
2065
- * Clears the deque.
2066
- */
2067
- clear(): void;
2068
- /**
2069
- * Returns an iterator for the deque.
2070
- *
2071
- * @returns An iterator for the deque.
2072
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
2073
- */
2074
- [Symbol.iterator](): Iterator<T>;
2075
- /**
2076
- * Returns an backward iterator for the deque.
2077
- *
2078
- * @returns An backward iterator for the deque.
2079
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
2080
- */
2081
- backward(): Iterable<T>;
2082
- private incrementSize;
2083
- }
2084
-
2085
- /**
2086
- * Returns safe host OS optimized estimate of the default amount of parallelism a pool should use.
2087
- * Always returns a value greater than zero.
2088
- *
2089
- * @returns The host OS optimized maximum pool size.
2090
- */
2091
- declare const availableParallelism: () => number;
2092
-
2093
2093
  export { AbstractPool, AbstractWorker, CircularArray, type ClusterPoolOptions, ClusterWorker, Deque, DynamicClusterPool, DynamicThreadPool, type ErrorHandler, type EventHandler, type EventLoopUtilizationMeasurementStatistics, type ExitHandler, FixedClusterPool, FixedThreadPool, type ILinkedListNode, 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, type PromiseResponseWrapper, type StrategyData, type StrategyPolicy, type Task, type TaskAsyncFunction, type TaskFunction, type TaskFunctionOperationResult, type TaskFunctions, type TaskPerformance, type TaskStatistics, type TaskStatisticsRequirements, type TaskSyncFunction, type TasksQueueOptions, type ThreadPoolOptions, ThreadWorker, WorkerChoiceStrategies, type WorkerChoiceStrategy, WorkerChoiceStrategyContext, type WorkerChoiceStrategyOptions, type WorkerError, type WorkerInfo, type WorkerNodeEventDetail, type WorkerNodeOptions, type WorkerOptions, type WorkerStatistics, type WorkerType, WorkerTypes, type WorkerUsage, type Writable, availableParallelism };