poolifier 2.6.36 → 2.6.38
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 +6 -3
- package/lib/index.d.ts +1881 -22
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/package.json +8 -7
- package/lib/circular-array.d.ts +0 -22
- package/lib/deque.d.ts +0 -80
- package/lib/pools/abstract-pool.d.ts +0 -314
- package/lib/pools/cluster/dynamic.d.ts +0 -29
- package/lib/pools/cluster/fixed.d.ts +0 -62
- package/lib/pools/pool.d.ts +0 -243
- package/lib/pools/selection-strategies/abstract-worker-choice-strategy.d.ts +0 -104
- package/lib/pools/selection-strategies/fair-share-worker-choice-strategy.d.ts +0 -39
- package/lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.d.ts +0 -39
- package/lib/pools/selection-strategies/least-busy-worker-choice-strategy.d.ts +0 -26
- package/lib/pools/selection-strategies/least-elu-worker-choice-strategy.d.ts +0 -26
- package/lib/pools/selection-strategies/least-used-worker-choice-strategy.d.ts +0 -24
- package/lib/pools/selection-strategies/round-robin-worker-choice-strategy.d.ts +0 -24
- package/lib/pools/selection-strategies/selection-strategies-types.d.ts +0 -200
- package/lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.d.ts +0 -35
- package/lib/pools/selection-strategies/worker-choice-strategy-context.d.ts +0 -71
- package/lib/pools/thread/dynamic.d.ts +0 -29
- package/lib/pools/thread/fixed.d.ts +0 -54
- package/lib/pools/version.d.ts +0 -1
- package/lib/pools/worker-node.d.ts +0 -69
- package/lib/pools/worker.d.ts +0 -276
- package/lib/utility-types.d.ts +0 -152
- package/lib/utils.d.ts +0 -115
- package/lib/worker/abstract-worker.d.ts +0 -191
- package/lib/worker/cluster-worker.d.ts +0 -35
- package/lib/worker/task-functions.d.ts +0 -33
- package/lib/worker/thread-worker.d.ts +0 -43
- package/lib/worker/worker-options.d.ts +0 -61
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enumeration of worker choice strategies.
|
|
3
|
-
*/
|
|
4
|
-
export declare const WorkerChoiceStrategies: Readonly<{
|
|
5
|
-
/**
|
|
6
|
-
* Round robin worker selection strategy.
|
|
7
|
-
*/
|
|
8
|
-
readonly ROUND_ROBIN: "ROUND_ROBIN";
|
|
9
|
-
/**
|
|
10
|
-
* Least used worker selection strategy.
|
|
11
|
-
*/
|
|
12
|
-
readonly LEAST_USED: "LEAST_USED";
|
|
13
|
-
/**
|
|
14
|
-
* Least busy worker selection strategy.
|
|
15
|
-
*/
|
|
16
|
-
readonly LEAST_BUSY: "LEAST_BUSY";
|
|
17
|
-
/**
|
|
18
|
-
* Least ELU worker selection strategy.
|
|
19
|
-
*/
|
|
20
|
-
readonly LEAST_ELU: "LEAST_ELU";
|
|
21
|
-
/**
|
|
22
|
-
* Fair share worker selection strategy.
|
|
23
|
-
*/
|
|
24
|
-
readonly FAIR_SHARE: "FAIR_SHARE";
|
|
25
|
-
/**
|
|
26
|
-
* Weighted round robin worker selection strategy.
|
|
27
|
-
*/
|
|
28
|
-
readonly WEIGHTED_ROUND_ROBIN: "WEIGHTED_ROUND_ROBIN";
|
|
29
|
-
/**
|
|
30
|
-
* Interleaved weighted round robin worker selection strategy.
|
|
31
|
-
*
|
|
32
|
-
* @experimental
|
|
33
|
-
*/
|
|
34
|
-
readonly INTERLEAVED_WEIGHTED_ROUND_ROBIN: "INTERLEAVED_WEIGHTED_ROUND_ROBIN";
|
|
35
|
-
}>;
|
|
36
|
-
/**
|
|
37
|
-
* Worker choice strategy.
|
|
38
|
-
*/
|
|
39
|
-
export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies;
|
|
40
|
-
/**
|
|
41
|
-
* Enumeration of measurements.
|
|
42
|
-
*/
|
|
43
|
-
export declare const Measurements: Readonly<{
|
|
44
|
-
readonly runTime: "runTime";
|
|
45
|
-
readonly waitTime: "waitTime";
|
|
46
|
-
readonly elu: "elu";
|
|
47
|
-
}>;
|
|
48
|
-
/**
|
|
49
|
-
* Measurement.
|
|
50
|
-
*/
|
|
51
|
-
export type Measurement = keyof typeof Measurements;
|
|
52
|
-
/**
|
|
53
|
-
* Measurement options.
|
|
54
|
-
*/
|
|
55
|
-
export interface MeasurementOptions {
|
|
56
|
-
/**
|
|
57
|
-
* Set measurement median.
|
|
58
|
-
*/
|
|
59
|
-
readonly median: boolean;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Worker choice strategy options.
|
|
63
|
-
*/
|
|
64
|
-
export interface WorkerChoiceStrategyOptions {
|
|
65
|
-
/**
|
|
66
|
-
* Number of worker choice retries to perform if no worker is eligible.
|
|
67
|
-
*
|
|
68
|
-
* @defaultValue 6
|
|
69
|
-
*/
|
|
70
|
-
readonly choiceRetries?: number;
|
|
71
|
-
/**
|
|
72
|
-
* Measurement to use in worker choice strategy supporting it.
|
|
73
|
-
*/
|
|
74
|
-
readonly measurement?: Measurement;
|
|
75
|
-
/**
|
|
76
|
-
* Runtime options.
|
|
77
|
-
*
|
|
78
|
-
* @defaultValue \{ median: false \}
|
|
79
|
-
*/
|
|
80
|
-
readonly runTime?: MeasurementOptions;
|
|
81
|
-
/**
|
|
82
|
-
* Wait time options.
|
|
83
|
-
*
|
|
84
|
-
* @defaultValue \{ median: false \}
|
|
85
|
-
*/
|
|
86
|
-
readonly waitTime?: MeasurementOptions;
|
|
87
|
-
/**
|
|
88
|
-
* Event loop utilization options.
|
|
89
|
-
*
|
|
90
|
-
* @defaultValue \{ median: false \}
|
|
91
|
-
*/
|
|
92
|
-
readonly elu?: MeasurementOptions;
|
|
93
|
-
/**
|
|
94
|
-
* Worker weights to use for weighted round robin worker selection strategies.
|
|
95
|
-
* A weight is tasks maximum execution time in milliseconds for a worker node.
|
|
96
|
-
*
|
|
97
|
-
* @defaultValue Weights computed automatically given the CPU performance.
|
|
98
|
-
*/
|
|
99
|
-
readonly weights?: Record<number, number>;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Measurement statistics requirements.
|
|
103
|
-
*
|
|
104
|
-
* @internal
|
|
105
|
-
*/
|
|
106
|
-
export interface MeasurementStatisticsRequirements {
|
|
107
|
-
/**
|
|
108
|
-
* Requires measurement aggregate.
|
|
109
|
-
*/
|
|
110
|
-
aggregate: boolean;
|
|
111
|
-
/**
|
|
112
|
-
* Requires measurement average.
|
|
113
|
-
*/
|
|
114
|
-
average: boolean;
|
|
115
|
-
/**
|
|
116
|
-
* Requires measurement median.
|
|
117
|
-
*/
|
|
118
|
-
median: boolean;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Pool worker node worker usage statistics requirements.
|
|
122
|
-
*
|
|
123
|
-
* @internal
|
|
124
|
-
*/
|
|
125
|
-
export interface TaskStatisticsRequirements {
|
|
126
|
-
/**
|
|
127
|
-
* Tasks runtime requirements.
|
|
128
|
-
*/
|
|
129
|
-
readonly runTime: MeasurementStatisticsRequirements;
|
|
130
|
-
/**
|
|
131
|
-
* Tasks wait time requirements.
|
|
132
|
-
*/
|
|
133
|
-
readonly waitTime: MeasurementStatisticsRequirements;
|
|
134
|
-
/**
|
|
135
|
-
* Tasks event loop utilization requirements.
|
|
136
|
-
*/
|
|
137
|
-
readonly elu: MeasurementStatisticsRequirements;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Strategy policy.
|
|
141
|
-
*
|
|
142
|
-
* @internal
|
|
143
|
-
*/
|
|
144
|
-
export interface StrategyPolicy {
|
|
145
|
-
/**
|
|
146
|
-
* Expects tasks execution on the newly created dynamic worker.
|
|
147
|
-
*/
|
|
148
|
-
readonly dynamicWorkerUsage: boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Expects the newly created dynamic worker to be flagged as ready.
|
|
151
|
-
*/
|
|
152
|
-
readonly dynamicWorkerReady: boolean;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Worker choice strategy interface.
|
|
156
|
-
*
|
|
157
|
-
* @internal
|
|
158
|
-
*/
|
|
159
|
-
export interface IWorkerChoiceStrategy {
|
|
160
|
-
/**
|
|
161
|
-
* Strategy policy.
|
|
162
|
-
*/
|
|
163
|
-
readonly strategyPolicy: StrategyPolicy;
|
|
164
|
-
/**
|
|
165
|
-
* Tasks statistics requirements.
|
|
166
|
-
*/
|
|
167
|
-
readonly taskStatisticsRequirements: TaskStatisticsRequirements;
|
|
168
|
-
/**
|
|
169
|
-
* Resets strategy internals.
|
|
170
|
-
*
|
|
171
|
-
* @returns `true` if the reset is successful, `false` otherwise.
|
|
172
|
-
*/
|
|
173
|
-
readonly reset: () => boolean;
|
|
174
|
-
/**
|
|
175
|
-
* Updates the worker node key strategy internals.
|
|
176
|
-
*
|
|
177
|
-
* @returns `true` if the update is successful, `false` otherwise.
|
|
178
|
-
*/
|
|
179
|
-
readonly update: (workerNodeKey: number) => boolean;
|
|
180
|
-
/**
|
|
181
|
-
* Chooses a worker node in the pool and returns its key.
|
|
182
|
-
* If the worker node is not eligible, `undefined` is returned.
|
|
183
|
-
*
|
|
184
|
-
* @returns The worker node key or `undefined`.
|
|
185
|
-
*/
|
|
186
|
-
readonly choose: () => number | undefined;
|
|
187
|
-
/**
|
|
188
|
-
* Removes the worker node key from strategy internals.
|
|
189
|
-
*
|
|
190
|
-
* @param workerNodeKey - The worker node key.
|
|
191
|
-
* @returns `true` if the worker node key is removed, `false` otherwise.
|
|
192
|
-
*/
|
|
193
|
-
readonly remove: (workerNodeKey: number) => boolean;
|
|
194
|
-
/**
|
|
195
|
-
* Sets the worker choice strategy options.
|
|
196
|
-
*
|
|
197
|
-
* @param opts - The worker choice strategy options.
|
|
198
|
-
*/
|
|
199
|
-
readonly setOptions: (opts: WorkerChoiceStrategyOptions) => void;
|
|
200
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { IWorker } from '../worker';
|
|
2
|
-
import type { IPool } from '../pool';
|
|
3
|
-
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy';
|
|
4
|
-
import type { IWorkerChoiceStrategy, TaskStatisticsRequirements, WorkerChoiceStrategyOptions } from './selection-strategies-types';
|
|
5
|
-
/**
|
|
6
|
-
* Selects the next worker with a weighted round robin scheduling algorithm.
|
|
7
|
-
* Loosely modeled after the weighted round robin queueing algorithm: https://en.wikipedia.org/wiki/Weighted_round_robin.
|
|
8
|
-
*
|
|
9
|
-
* @typeParam Worker - Type of worker which manages the strategy.
|
|
10
|
-
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
11
|
-
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
12
|
-
*/
|
|
13
|
-
export declare class WeightedRoundRobinWorkerChoiceStrategy<Worker extends IWorker, Data = unknown, Response = unknown> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> implements IWorkerChoiceStrategy {
|
|
14
|
-
/** @inheritDoc */
|
|
15
|
-
readonly taskStatisticsRequirements: TaskStatisticsRequirements;
|
|
16
|
-
/**
|
|
17
|
-
* Default worker weight.
|
|
18
|
-
*/
|
|
19
|
-
private readonly defaultWorkerWeight;
|
|
20
|
-
/**
|
|
21
|
-
* Worker virtual task runtime.
|
|
22
|
-
*/
|
|
23
|
-
private workerVirtualTaskRunTime;
|
|
24
|
-
/** @inheritDoc */
|
|
25
|
-
constructor(pool: IPool<Worker, Data, Response>, opts?: WorkerChoiceStrategyOptions);
|
|
26
|
-
/** @inheritDoc */
|
|
27
|
-
reset(): boolean;
|
|
28
|
-
/** @inheritDoc */
|
|
29
|
-
update(): boolean;
|
|
30
|
-
/** @inheritDoc */
|
|
31
|
-
choose(): number | undefined;
|
|
32
|
-
/** @inheritDoc */
|
|
33
|
-
remove(workerNodeKey: number): boolean;
|
|
34
|
-
private weightedRoundRobinNextWorkerNodeKey;
|
|
35
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { IPool } from '../pool';
|
|
2
|
-
import type { IWorker } from '../worker';
|
|
3
|
-
import type { StrategyPolicy, TaskStatisticsRequirements, WorkerChoiceStrategy, WorkerChoiceStrategyOptions } from './selection-strategies-types';
|
|
4
|
-
/**
|
|
5
|
-
* The worker choice strategy context.
|
|
6
|
-
*
|
|
7
|
-
* @typeParam Worker - Type of worker.
|
|
8
|
-
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
9
|
-
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
10
|
-
*/
|
|
11
|
-
export declare class WorkerChoiceStrategyContext<Worker extends IWorker, Data = unknown, Response = unknown> {
|
|
12
|
-
private workerChoiceStrategy;
|
|
13
|
-
private opts;
|
|
14
|
-
private readonly workerChoiceStrategies;
|
|
15
|
-
/**
|
|
16
|
-
* The number of times the worker choice strategy in the context has been retried.
|
|
17
|
-
*/
|
|
18
|
-
private choiceRetriesCount;
|
|
19
|
-
/**
|
|
20
|
-
* Worker choice strategy context constructor.
|
|
21
|
-
*
|
|
22
|
-
* @param pool - The pool instance.
|
|
23
|
-
* @param workerChoiceStrategy - The worker choice strategy.
|
|
24
|
-
* @param opts - The worker choice strategy options.
|
|
25
|
-
*/
|
|
26
|
-
constructor(pool: IPool<Worker, Data, Response>, workerChoiceStrategy?: WorkerChoiceStrategy, opts?: WorkerChoiceStrategyOptions);
|
|
27
|
-
/**
|
|
28
|
-
* Gets the strategy policy in the context.
|
|
29
|
-
*
|
|
30
|
-
* @returns The strategy policy.
|
|
31
|
-
*/
|
|
32
|
-
getStrategyPolicy(): StrategyPolicy;
|
|
33
|
-
/**
|
|
34
|
-
* Gets the worker choice strategy in the context task statistics requirements.
|
|
35
|
-
*
|
|
36
|
-
* @returns The task statistics requirements.
|
|
37
|
-
*/
|
|
38
|
-
getTaskStatisticsRequirements(): TaskStatisticsRequirements;
|
|
39
|
-
/**
|
|
40
|
-
* Sets the worker choice strategy to use in the context.
|
|
41
|
-
*
|
|
42
|
-
* @param workerChoiceStrategy - The worker choice strategy to set.
|
|
43
|
-
*/
|
|
44
|
-
setWorkerChoiceStrategy(workerChoiceStrategy: WorkerChoiceStrategy): void;
|
|
45
|
-
/**
|
|
46
|
-
* Updates the worker node key in the worker choice strategy in the context internals.
|
|
47
|
-
*
|
|
48
|
-
* @returns `true` if the update is successful, `false` otherwise.
|
|
49
|
-
*/
|
|
50
|
-
update(workerNodeKey: number): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Executes the worker choice strategy in the context algorithm.
|
|
53
|
-
*
|
|
54
|
-
* @returns The key of the worker node.
|
|
55
|
-
* @throws {@link https://nodejs.org/api/errors.html#class-error} If after configured retries the worker node key is null or undefined .
|
|
56
|
-
*/
|
|
57
|
-
execute(): number;
|
|
58
|
-
/**
|
|
59
|
-
* Removes the worker node key from the worker choice strategy in the context.
|
|
60
|
-
*
|
|
61
|
-
* @param workerNodeKey - The worker node key.
|
|
62
|
-
* @returns `true` if the removal is successful, `false` otherwise.
|
|
63
|
-
*/
|
|
64
|
-
remove(workerNodeKey: number): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Sets the worker choice strategies in the context options.
|
|
67
|
-
*
|
|
68
|
-
* @param opts - The worker choice strategy options.
|
|
69
|
-
*/
|
|
70
|
-
setOptions(opts: WorkerChoiceStrategyOptions): void;
|
|
71
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type PoolType } from '../pool';
|
|
2
|
-
import { FixedThreadPool, type ThreadPoolOptions } from './fixed';
|
|
3
|
-
/**
|
|
4
|
-
* A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads.
|
|
5
|
-
*
|
|
6
|
-
* This thread pool creates new threads when the others are busy, up to the maximum number of threads.
|
|
7
|
-
* 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`.
|
|
8
|
-
*
|
|
9
|
-
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
10
|
-
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
11
|
-
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
|
|
12
|
-
* @since 0.0.1
|
|
13
|
-
*/
|
|
14
|
-
export declare class DynamicThreadPool<Data = unknown, Response = unknown> extends FixedThreadPool<Data, Response> {
|
|
15
|
-
protected readonly max: number;
|
|
16
|
-
/**
|
|
17
|
-
* Constructs a new poolifier dynamic thread pool.
|
|
18
|
-
*
|
|
19
|
-
* @param min - Minimum number of threads which are always active.
|
|
20
|
-
* @param max - Maximum number of threads that can be created by this pool.
|
|
21
|
-
* @param filePath - Path to an implementation of a `ThreadWorker` file, which can be relative or absolute.
|
|
22
|
-
* @param opts - Options for this dynamic thread pool.
|
|
23
|
-
*/
|
|
24
|
-
constructor(min: number, max: number, filePath: string, opts?: ThreadPoolOptions);
|
|
25
|
-
/** @inheritDoc */
|
|
26
|
-
protected get type(): PoolType;
|
|
27
|
-
/** @inheritDoc */
|
|
28
|
-
protected get busy(): boolean;
|
|
29
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { type TransferListItem, Worker, type WorkerOptions } from 'node:worker_threads';
|
|
3
|
-
import type { MessageValue } from '../../utility-types';
|
|
4
|
-
import { AbstractPool } from '../abstract-pool';
|
|
5
|
-
import { type PoolOptions, type PoolType } from '../pool';
|
|
6
|
-
import { type WorkerType } from '../worker';
|
|
7
|
-
/**
|
|
8
|
-
* Options for a poolifier thread pool.
|
|
9
|
-
*/
|
|
10
|
-
export interface ThreadPoolOptions extends PoolOptions<Worker> {
|
|
11
|
-
/**
|
|
12
|
-
* Worker options.
|
|
13
|
-
*
|
|
14
|
-
* @see https://nodejs.org/api/worker_threads.html#new-workerfilename-options
|
|
15
|
-
*/
|
|
16
|
-
workerOptions?: WorkerOptions;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A thread pool with a fixed number of threads.
|
|
20
|
-
*
|
|
21
|
-
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
22
|
-
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
|
|
23
|
-
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
|
|
24
|
-
* @since 0.0.1
|
|
25
|
-
*/
|
|
26
|
-
export declare class FixedThreadPool<Data = unknown, Response = unknown> extends AbstractPool<Worker, Data, Response> {
|
|
27
|
-
protected readonly opts: ThreadPoolOptions;
|
|
28
|
-
/**
|
|
29
|
-
* Constructs a new poolifier fixed thread pool.
|
|
30
|
-
*
|
|
31
|
-
* @param numberOfThreads - Number of threads for this pool.
|
|
32
|
-
* @param filePath - Path to an implementation of a `ThreadWorker` file, which can be relative or absolute.
|
|
33
|
-
* @param opts - Options for this fixed thread pool.
|
|
34
|
-
*/
|
|
35
|
-
constructor(numberOfThreads: number, filePath: string, opts?: ThreadPoolOptions);
|
|
36
|
-
/** @inheritDoc */
|
|
37
|
-
protected isMain(): boolean;
|
|
38
|
-
/** @inheritDoc */
|
|
39
|
-
protected destroyWorkerNode(workerNodeKey: number): Promise<void>;
|
|
40
|
-
/** @inheritDoc */
|
|
41
|
-
protected sendToWorker(workerNodeKey: number, message: MessageValue<Data>, transferList?: TransferListItem[]): void;
|
|
42
|
-
/** @inheritDoc */
|
|
43
|
-
protected sendStartupMessageToWorker(workerNodeKey: number): void;
|
|
44
|
-
/** @inheritDoc */
|
|
45
|
-
protected registerWorkerMessageListener<Message extends Data | Response>(workerNodeKey: number, listener: (message: MessageValue<Message>) => void): void;
|
|
46
|
-
/** @inheritDoc */
|
|
47
|
-
protected createWorker(): Worker;
|
|
48
|
-
/** @inheritDoc */
|
|
49
|
-
protected get type(): PoolType;
|
|
50
|
-
/** @inheritDoc */
|
|
51
|
-
protected get worker(): WorkerType;
|
|
52
|
-
/** @inheritDoc */
|
|
53
|
-
protected get busy(): boolean;
|
|
54
|
-
}
|
package/lib/pools/version.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const version = "2.6.36";
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { MessageChannel } from 'node:worker_threads';
|
|
3
|
-
import type { Task } from '../utility-types';
|
|
4
|
-
import { type IWorker, type IWorkerNode, type WorkerInfo, type WorkerType, type WorkerUsage } from './worker';
|
|
5
|
-
/**
|
|
6
|
-
* Worker node.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam Worker - Type of worker.
|
|
9
|
-
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
|
|
10
|
-
*/
|
|
11
|
-
export declare class WorkerNode<Worker extends IWorker, Data = unknown> implements IWorkerNode<Worker, Data> {
|
|
12
|
-
/** @inheritdoc */
|
|
13
|
-
readonly worker: Worker;
|
|
14
|
-
/** @inheritdoc */
|
|
15
|
-
readonly info: WorkerInfo;
|
|
16
|
-
/** @inheritdoc */
|
|
17
|
-
usage: WorkerUsage;
|
|
18
|
-
/** @inheritdoc */
|
|
19
|
-
messageChannel?: MessageChannel;
|
|
20
|
-
/** @inheritdoc */
|
|
21
|
-
tasksQueueBackPressureSize: number;
|
|
22
|
-
/** @inheritdoc */
|
|
23
|
-
onBackPressure?: (workerId: number) => void;
|
|
24
|
-
/** @inheritdoc */
|
|
25
|
-
onEmptyQueue?: (workerId: number) => void;
|
|
26
|
-
private readonly tasksQueue;
|
|
27
|
-
private onEmptyQueueCount;
|
|
28
|
-
private readonly taskFunctionsUsage;
|
|
29
|
-
/**
|
|
30
|
-
* Constructs a new worker node.
|
|
31
|
-
*
|
|
32
|
-
* @param worker - The worker.
|
|
33
|
-
* @param workerType - The worker type.
|
|
34
|
-
* @param tasksQueueBackPressureSize - The tasks queue back pressure size.
|
|
35
|
-
*/
|
|
36
|
-
constructor(worker: Worker, workerType: WorkerType, tasksQueueBackPressureSize: number);
|
|
37
|
-
/** @inheritdoc */
|
|
38
|
-
tasksQueueSize(): number;
|
|
39
|
-
/** @inheritdoc */
|
|
40
|
-
enqueueTask(task: Task<Data>): number;
|
|
41
|
-
/** @inheritdoc */
|
|
42
|
-
unshiftTask(task: Task<Data>): number;
|
|
43
|
-
/** @inheritdoc */
|
|
44
|
-
dequeueTask(): Task<Data> | undefined;
|
|
45
|
-
/** @inheritdoc */
|
|
46
|
-
popTask(): Task<Data> | undefined;
|
|
47
|
-
/** @inheritdoc */
|
|
48
|
-
clearTasksQueue(): void;
|
|
49
|
-
/** @inheritdoc */
|
|
50
|
-
hasBackPressure(): boolean;
|
|
51
|
-
/** @inheritdoc */
|
|
52
|
-
resetUsage(): void;
|
|
53
|
-
/** @inheritdoc */
|
|
54
|
-
closeChannel(): void;
|
|
55
|
-
/** @inheritdoc */
|
|
56
|
-
getTaskFunctionWorkerUsage(name: string): WorkerUsage | undefined;
|
|
57
|
-
private startOnEmptyQueue;
|
|
58
|
-
private initWorkerInfo;
|
|
59
|
-
private initWorkerUsage;
|
|
60
|
-
private initTaskFunctionWorkerUsage;
|
|
61
|
-
/**
|
|
62
|
-
* Gets the worker id.
|
|
63
|
-
*
|
|
64
|
-
* @param worker - The worker.
|
|
65
|
-
* @param workerType - The worker type.
|
|
66
|
-
* @returns The worker id.
|
|
67
|
-
*/
|
|
68
|
-
private getWorkerId;
|
|
69
|
-
}
|