@common.js/p-queue 7.4.1 → 9.3.1
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 -1
- package/dist/index.d.ts +189 -19
- package/dist/index.js +1030 -296
- package/dist/options.d.ts +53 -18
- package/dist/priority-queue.d.ts +7 -4
- package/dist/priority-queue.js +216 -51
- package/dist/queue.d.ts +5 -3
- package/package.json +26 -33
package/dist/options.d.ts
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import { Queue, RunFunction } from './queue.js';
|
|
2
|
-
|
|
1
|
+
import { type Queue, type RunFunction } from './queue.js';
|
|
2
|
+
type TimeoutOptions = {
|
|
3
3
|
/**
|
|
4
|
-
Per-operation timeout in milliseconds. Operations
|
|
5
|
-
*/
|
|
6
|
-
timeout?: number;
|
|
7
|
-
/**
|
|
8
|
-
Whether or not a timeout is considered an exception.
|
|
4
|
+
Per-operation timeout in milliseconds. Operations will throw a `TimeoutError` if they don't complete within the specified time.
|
|
9
5
|
|
|
10
|
-
|
|
6
|
+
The timeout begins when the operation is dequeued and starts execution, not while it's waiting in the queue.
|
|
7
|
+
|
|
8
|
+
@default undefined
|
|
9
|
+
|
|
10
|
+
Can be overridden per task using the `timeout` option in `.add()`:
|
|
11
|
+
|
|
12
|
+
@example
|
|
13
|
+
```
|
|
14
|
+
const queue = new PQueue({timeout: 5000});
|
|
15
|
+
|
|
16
|
+
// This task uses the global 5s timeout
|
|
17
|
+
await queue.add(() => fetchData());
|
|
18
|
+
|
|
19
|
+
// This task has a 10s timeout
|
|
20
|
+
await queue.add(() => slowTask(), {timeout: 10000});
|
|
21
|
+
```
|
|
11
22
|
*/
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
export
|
|
23
|
+
timeout?: number;
|
|
24
|
+
};
|
|
25
|
+
export type Options<QueueType extends Queue<RunFunction, QueueOptions>, QueueOptions extends QueueAddOptions> = {
|
|
15
26
|
/**
|
|
16
27
|
Concurrency limit.
|
|
17
28
|
|
|
@@ -21,7 +32,7 @@ export interface Options<QueueType extends Queue<RunFunction, QueueOptions>, Que
|
|
|
21
32
|
*/
|
|
22
33
|
readonly concurrency?: number;
|
|
23
34
|
/**
|
|
24
|
-
Whether queue tasks within concurrency limit
|
|
35
|
+
Whether queue tasks within the concurrency limit are auto-executed as soon as they're added.
|
|
25
36
|
|
|
26
37
|
@default true
|
|
27
38
|
*/
|
|
@@ -51,17 +62,41 @@ export interface Options<QueueType extends Queue<RunFunction, QueueOptions>, Que
|
|
|
51
62
|
|
|
52
63
|
@default false
|
|
53
64
|
*/
|
|
65
|
+
readonly carryoverIntervalCount?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
@deprecated Renamed to `carryoverIntervalCount`.
|
|
68
|
+
*/
|
|
54
69
|
readonly carryoverConcurrencyCount?: boolean;
|
|
55
|
-
|
|
56
|
-
|
|
70
|
+
/**
|
|
71
|
+
Whether to use strict mode for rate limiting (sliding window algorithm).
|
|
72
|
+
|
|
73
|
+
When enabled, ensures that no more than `intervalCap` tasks execute in any rolling `interval` window, rather than resetting the count at fixed intervals. This provides more predictable and evenly distributed execution.
|
|
74
|
+
|
|
75
|
+
@default false
|
|
76
|
+
|
|
77
|
+
For example, with `intervalCap: 2` and `interval: 1000`:
|
|
78
|
+
- __Default mode (fixed window)__: Tasks can burst at window boundaries. You could execute 2 tasks at 999ms and 2 more at 1000ms, resulting in 4 tasks within 1ms.
|
|
79
|
+
- __Strict mode (sliding window)__: Enforces that no more than 2 tasks execute in any 1000ms rolling window, preventing bursts.
|
|
80
|
+
|
|
81
|
+
Strict mode is more resource-intensive as it tracks individual execution timestamps. Use it when you need guaranteed rate-limit compliance, such as when interacting with APIs that enforce strict rate limits.
|
|
82
|
+
|
|
83
|
+
The `carryoverIntervalCount` option has no effect when `strict` mode is enabled, as strict mode tracks actual execution timestamps rather than counting pending tasks.
|
|
84
|
+
*/
|
|
85
|
+
readonly strict?: boolean;
|
|
86
|
+
} & TimeoutOptions;
|
|
87
|
+
export type QueueAddOptions = {
|
|
57
88
|
/**
|
|
58
89
|
Priority of operation. Operations with greater priority will be scheduled first.
|
|
59
90
|
|
|
60
91
|
@default 0
|
|
61
92
|
*/
|
|
62
93
|
readonly priority?: number;
|
|
63
|
-
|
|
64
|
-
|
|
94
|
+
/**
|
|
95
|
+
Unique identifier for the promise function, used to update its priority before execution. If not specified, it is auto-assigned an incrementing BigInt starting from `1n`.
|
|
96
|
+
*/
|
|
97
|
+
id?: string;
|
|
98
|
+
} & TaskOptions & TimeoutOptions;
|
|
99
|
+
export type TaskOptions = {
|
|
65
100
|
/**
|
|
66
101
|
[`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) for cancellation of the operation. When aborted, it will be removed from the queue and the `queue.add()` call will reject with an `AbortError`. If the operation is already running, the signal will need to be handled by the operation itself.
|
|
67
102
|
|
|
@@ -97,6 +132,6 @@ export interface TaskOptions {
|
|
|
97
132
|
}
|
|
98
133
|
```
|
|
99
134
|
*/
|
|
100
|
-
readonly signal?: AbortSignal;
|
|
101
|
-
}
|
|
135
|
+
readonly signal?: AbortSignal | undefined;
|
|
136
|
+
};
|
|
102
137
|
export {};
|
package/dist/priority-queue.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Queue, RunFunction } from './queue.js';
|
|
2
|
-
import { QueueAddOptions } from './options.js';
|
|
3
|
-
export
|
|
1
|
+
import { type Queue, type RunFunction } from './queue.js';
|
|
2
|
+
import { type QueueAddOptions } from './options.js';
|
|
3
|
+
export type PriorityQueueOptions = {
|
|
4
4
|
priority?: number;
|
|
5
|
-
}
|
|
5
|
+
} & QueueAddOptions;
|
|
6
6
|
export default class PriorityQueue implements Queue<RunFunction, PriorityQueueOptions> {
|
|
7
7
|
#private;
|
|
8
8
|
enqueue(run: RunFunction, options?: Partial<PriorityQueueOptions>): void;
|
|
9
|
+
setPriority(id: string, priority: number): void;
|
|
10
|
+
remove(id: string): void;
|
|
11
|
+
remove(run: RunFunction): void;
|
|
9
12
|
dequeue(): RunFunction | undefined;
|
|
10
13
|
filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[];
|
|
11
14
|
get size(): number;
|
package/dist/priority-queue.js
CHANGED
|
@@ -5,15 +5,97 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
Object.defineProperty(exports, "default", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return PriorityQueue;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _lowerBoundJs = /*#__PURE__*/ _interopRequireDefault(require("./lower-bound.js"));
|
|
12
|
+
function _arrayLikeToArray(arr, len) {
|
|
13
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
14
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
15
|
+
return arr2;
|
|
16
|
+
}
|
|
17
|
+
function _arrayWithHoles(arr) {
|
|
18
|
+
if (Array.isArray(arr)) return arr;
|
|
19
|
+
}
|
|
20
|
+
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
21
|
+
if (privateCollection.has(obj)) {
|
|
22
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
26
|
+
if (descriptor.get) {
|
|
27
|
+
return descriptor.get.call(receiver);
|
|
28
|
+
}
|
|
29
|
+
return descriptor.value;
|
|
30
|
+
}
|
|
31
|
+
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
32
|
+
if (descriptor.set) {
|
|
33
|
+
descriptor.set.call(receiver, value);
|
|
34
|
+
} else {
|
|
35
|
+
if (!descriptor.writable) {
|
|
36
|
+
throw new TypeError("attempted to set read only private field");
|
|
37
|
+
}
|
|
38
|
+
descriptor.value = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function _classApplyDescriptorUpdate(receiver, descriptor) {
|
|
42
|
+
if (descriptor.set) {
|
|
43
|
+
if (!("__destrWrapper" in descriptor)) {
|
|
44
|
+
descriptor.__destrWrapper = {
|
|
45
|
+
set value (v){
|
|
46
|
+
descriptor.set.call(receiver, v);
|
|
47
|
+
},
|
|
48
|
+
get value () {
|
|
49
|
+
return descriptor.get.call(receiver);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return descriptor.__destrWrapper;
|
|
54
|
+
} else {
|
|
55
|
+
if (!descriptor.writable) {
|
|
56
|
+
throw new TypeError("attempted to set read only private field");
|
|
57
|
+
}
|
|
58
|
+
return descriptor;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
12
61
|
function _classCallCheck(instance, Constructor) {
|
|
13
62
|
if (!(instance instanceof Constructor)) {
|
|
14
63
|
throw new TypeError("Cannot call a class as a function");
|
|
15
64
|
}
|
|
16
65
|
}
|
|
66
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
67
|
+
if (!privateMap.has(receiver)) {
|
|
68
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
69
|
+
}
|
|
70
|
+
return privateMap.get(receiver);
|
|
71
|
+
}
|
|
72
|
+
function _classPrivateFieldGet(receiver, privateMap) {
|
|
73
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
74
|
+
return _classApplyDescriptorGet(receiver, descriptor);
|
|
75
|
+
}
|
|
76
|
+
function _classPrivateFieldInit(obj, privateMap, value) {
|
|
77
|
+
_checkPrivateRedeclaration(obj, privateMap);
|
|
78
|
+
privateMap.set(obj, value);
|
|
79
|
+
}
|
|
80
|
+
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
81
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
82
|
+
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
function _classPrivateFieldUpdate(receiver, privateMap) {
|
|
86
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "update");
|
|
87
|
+
return _classApplyDescriptorUpdate(receiver, descriptor);
|
|
88
|
+
}
|
|
89
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) {
|
|
90
|
+
if (!privateSet.has(receiver)) {
|
|
91
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
92
|
+
}
|
|
93
|
+
return fn;
|
|
94
|
+
}
|
|
95
|
+
function _classPrivateMethodInit(obj, privateSet) {
|
|
96
|
+
_checkPrivateRedeclaration(obj, privateSet);
|
|
97
|
+
privateSet.add(obj);
|
|
98
|
+
}
|
|
17
99
|
function _defineProperties(target, props) {
|
|
18
100
|
for(var i = 0; i < props.length; i++){
|
|
19
101
|
var descriptor = props[i];
|
|
@@ -28,97 +110,180 @@ function _createClass(Constructor, protoProps, staticProps) {
|
|
|
28
110
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
29
111
|
return Constructor;
|
|
30
112
|
}
|
|
31
|
-
function _defineProperty(obj, key, value) {
|
|
32
|
-
if (key in obj) {
|
|
33
|
-
Object.defineProperty(obj, key, {
|
|
34
|
-
value: value,
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true
|
|
38
|
-
});
|
|
39
|
-
} else {
|
|
40
|
-
obj[key] = value;
|
|
41
|
-
}
|
|
42
|
-
return obj;
|
|
43
|
-
}
|
|
44
113
|
function _interopRequireDefault(obj) {
|
|
45
114
|
return obj && obj.__esModule ? obj : {
|
|
46
115
|
default: obj
|
|
47
116
|
};
|
|
48
117
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
118
|
+
function _iterableToArrayLimit(arr, i) {
|
|
119
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
120
|
+
if (_i == null) return;
|
|
121
|
+
var _arr = [];
|
|
122
|
+
var _n = true;
|
|
123
|
+
var _d = false;
|
|
124
|
+
var _s, _e;
|
|
125
|
+
try {
|
|
126
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
127
|
+
_arr.push(_s.value);
|
|
128
|
+
if (i && _arr.length === i) break;
|
|
129
|
+
}
|
|
130
|
+
} catch (err) {
|
|
131
|
+
_d = true;
|
|
132
|
+
_e = err;
|
|
133
|
+
} finally{
|
|
134
|
+
try {
|
|
135
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
136
|
+
} finally{
|
|
137
|
+
if (_d) throw _e;
|
|
57
138
|
}
|
|
58
|
-
ownKeys.forEach(function(key) {
|
|
59
|
-
_defineProperty(target, key, source[key]);
|
|
60
|
-
});
|
|
61
139
|
}
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
140
|
+
return _arr;
|
|
141
|
+
}
|
|
142
|
+
function _nonIterableRest() {
|
|
143
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
144
|
+
}
|
|
145
|
+
function _slicedToArray(arr, i) {
|
|
146
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
147
|
+
}
|
|
148
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
149
|
+
if (!o) return;
|
|
150
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
151
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
152
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
153
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
154
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
155
|
+
}
|
|
156
|
+
var compactionThreshold = 100;
|
|
157
|
+
var _queue = /*#__PURE__*/ new WeakMap(), // The queue is stored as a sorted array, but dequeued items are left before `#head` until compaction. Only items from `#head` onward are live, which keeps repeated dequeues amortized O(1).
|
|
158
|
+
_head = /*#__PURE__*/ new WeakMap(), _compact = /*#__PURE__*/ new WeakSet();
|
|
70
159
|
var PriorityQueue = /*#__PURE__*/ function() {
|
|
71
160
|
"use strict";
|
|
72
161
|
function PriorityQueue() {
|
|
73
162
|
_classCallCheck(this, PriorityQueue);
|
|
74
|
-
|
|
163
|
+
_classPrivateMethodInit(this, _compact);
|
|
164
|
+
_classPrivateFieldInit(this, _queue, {
|
|
165
|
+
writable: true,
|
|
166
|
+
value: []
|
|
167
|
+
});
|
|
168
|
+
_classPrivateFieldInit(this, _head, {
|
|
169
|
+
writable: true,
|
|
170
|
+
value: 0
|
|
171
|
+
});
|
|
75
172
|
}
|
|
76
173
|
_createClass(PriorityQueue, [
|
|
77
174
|
{
|
|
78
175
|
key: "enqueue",
|
|
79
176
|
value: function enqueue(run, options) {
|
|
80
|
-
options =
|
|
81
|
-
|
|
82
|
-
}, options);
|
|
177
|
+
var ref = options !== null && options !== void 0 ? options : {}, _priority = ref.priority, priority = _priority === void 0 ? 0 : _priority, id = ref.id;
|
|
178
|
+
var size = this.size;
|
|
83
179
|
var element = {
|
|
84
|
-
priority:
|
|
180
|
+
priority: priority,
|
|
181
|
+
id: id,
|
|
85
182
|
run: run
|
|
86
183
|
};
|
|
87
|
-
if (
|
|
88
|
-
|
|
184
|
+
if (size === 0) {
|
|
185
|
+
// When the queue is logically empty, discard any consumed prefix before accepting new work.
|
|
186
|
+
_classPrivateFieldGet(this, _queue).length = 0;
|
|
187
|
+
_classPrivateFieldSet(this, _head, 0);
|
|
188
|
+
_classPrivateFieldGet(this, _queue).push(element);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (_classPrivateFieldGet(this, _queue).at(-1).priority >= priority) {
|
|
192
|
+
// Same-priority and lower-priority items belong after the current tail. Appending preserves FIFO order for equal priorities.
|
|
193
|
+
_classPrivateFieldGet(this, _queue).push(element);
|
|
89
194
|
return;
|
|
90
195
|
}
|
|
91
|
-
|
|
196
|
+
// Binary insertion must run on the live sorted range only.
|
|
197
|
+
_classPrivateMethodGet(this, _compact, compact).call(this);
|
|
198
|
+
var index = (0, _lowerBoundJs.default)(_classPrivateFieldGet(this, _queue), element, function(a, b) {
|
|
92
199
|
return b.priority - a.priority;
|
|
93
200
|
});
|
|
94
|
-
|
|
201
|
+
_classPrivateFieldGet(this, _queue).splice(index, 0, element);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
key: "setPriority",
|
|
206
|
+
value: function setPriority(id, priority) {
|
|
207
|
+
var _this = this;
|
|
208
|
+
// A dequeued item with the same id is no longer part of the queue.
|
|
209
|
+
var index = _classPrivateFieldGet(this, _queue).findIndex(function(element, index) {
|
|
210
|
+
return index >= _classPrivateFieldGet(_this, _head) && element.id === id;
|
|
211
|
+
});
|
|
212
|
+
if (index === -1) {
|
|
213
|
+
throw new ReferenceError('No promise function with the id "'.concat(id, '" exists in the queue.'));
|
|
214
|
+
}
|
|
215
|
+
var ref = _slicedToArray(_classPrivateFieldGet(this, _queue).splice(index, 1), 1), item = ref[0];
|
|
216
|
+
this.enqueue(item.run, {
|
|
217
|
+
priority: priority,
|
|
218
|
+
id: id
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
key: "remove",
|
|
224
|
+
value: function remove(idOrRun) {
|
|
225
|
+
var _this = this;
|
|
226
|
+
var index = _classPrivateFieldGet(this, _queue).findIndex(function(element, index) {
|
|
227
|
+
// The consumed prefix may still contain references that should not be removable.
|
|
228
|
+
if (index < _classPrivateFieldGet(_this, _head)) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
if (typeof idOrRun === "string") {
|
|
232
|
+
return element.id === idOrRun;
|
|
233
|
+
}
|
|
234
|
+
return element.run === idOrRun;
|
|
235
|
+
});
|
|
236
|
+
if (index !== -1) {
|
|
237
|
+
_classPrivateFieldGet(this, _queue).splice(index, 1);
|
|
238
|
+
}
|
|
95
239
|
}
|
|
96
240
|
},
|
|
97
241
|
{
|
|
98
242
|
key: "dequeue",
|
|
99
243
|
value: function dequeue() {
|
|
100
|
-
|
|
244
|
+
if (_classPrivateFieldGet(this, _head) === _classPrivateFieldGet(this, _queue).length) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
var item = _classPrivateFieldGet(this, _queue)[_classPrivateFieldGet(this, _head)];
|
|
248
|
+
_classPrivateFieldUpdate(this, _head).value++;
|
|
249
|
+
if (_classPrivateFieldGet(this, _head) === _classPrivateFieldGet(this, _queue).length) {
|
|
250
|
+
// Fully drained queues are reset immediately so the next enqueue starts from a clean array.
|
|
251
|
+
_classPrivateFieldGet(this, _queue).length = 0;
|
|
252
|
+
_classPrivateFieldSet(this, _head, 0);
|
|
253
|
+
} else if (_classPrivateFieldGet(this, _head) > compactionThreshold && _classPrivateFieldGet(this, _head) > _classPrivateFieldGet(this, _queue).length / 2) {
|
|
254
|
+
// Keep repeated dequeues cheap, but stop the consumed prefix from growing without bound.
|
|
255
|
+
_classPrivateMethodGet(this, _compact, compact).call(this);
|
|
256
|
+
}
|
|
101
257
|
return item === null || item === void 0 ? void 0 : item.run;
|
|
102
258
|
}
|
|
103
259
|
},
|
|
104
260
|
{
|
|
105
261
|
key: "filter",
|
|
106
262
|
value: function filter(options) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
263
|
+
var result = [];
|
|
264
|
+
for(var index = _classPrivateFieldGet(this, _head); index < _classPrivateFieldGet(this, _queue).length; index++){
|
|
265
|
+
var element = _classPrivateFieldGet(this, _queue)[index];
|
|
266
|
+
if (element.priority === options.priority) {
|
|
267
|
+
result.push(element.run);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return result;
|
|
112
271
|
}
|
|
113
272
|
},
|
|
114
273
|
{
|
|
115
274
|
key: "size",
|
|
116
275
|
get: function get() {
|
|
117
|
-
return
|
|
276
|
+
return _classPrivateFieldGet(this, _queue).length - _classPrivateFieldGet(this, _head);
|
|
118
277
|
}
|
|
119
278
|
}
|
|
120
279
|
]);
|
|
121
280
|
return PriorityQueue;
|
|
122
281
|
}();
|
|
123
|
-
|
|
124
|
-
|
|
282
|
+
function compact() {
|
|
283
|
+
// Compaction restores the invariant that the whole array is the live sorted range.
|
|
284
|
+
if (_classPrivateFieldGet(this, _head) === 0) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
_classPrivateFieldGet(this, _queue).splice(0, _classPrivateFieldGet(this, _head));
|
|
288
|
+
_classPrivateFieldSet(this, _head, 0);
|
|
289
|
+
}
|
package/dist/queue.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export type RunFunction = () => Promise<unknown>;
|
|
2
|
-
export
|
|
2
|
+
export type Queue<Element, Options> = {
|
|
3
3
|
size: number;
|
|
4
|
-
filter: (options: Partial<Options
|
|
4
|
+
filter: (options: Readonly<Partial<Options>>) => Element[];
|
|
5
5
|
dequeue: () => Element | undefined;
|
|
6
6
|
enqueue: (run: Element, options?: Partial<Options>) => void;
|
|
7
|
-
|
|
7
|
+
setPriority: (id: string, priority: number) => void;
|
|
8
|
+
remove?: (id: string) => void;
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -1,61 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common.js/p-queue",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.3.1",
|
|
4
4
|
"description": "p-queue package exported as CommonJS modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "etienne-martin/common.js",
|
|
7
7
|
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
8
|
"type": "commonjs",
|
|
9
|
+
"sideEffects": false,
|
|
9
10
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
11
|
+
"node": ">=20"
|
|
11
12
|
},
|
|
12
13
|
"scripts": {
|
|
13
14
|
"build": "del-cli dist && tsc",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"bench": "node --loader=ts-node/esm bench.ts"
|
|
15
|
+
"test": "xo && node --import=tsx/esm --test test/*.ts && del-cli dist && tsc && tsd",
|
|
16
|
+
"bench": "node --import=tsx/esm bench.ts"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
|
-
"types": "dist/index.d.ts",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"eventemitter3": "^5.0.
|
|
24
|
-
"@common.js/p-timeout": "^
|
|
23
|
+
"eventemitter3": "^5.0.4",
|
|
24
|
+
"@common.js/p-timeout": "^7.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@sindresorhus/tsconfig": "^
|
|
28
|
-
"@types/benchmark": "^2.1.
|
|
29
|
-
"@types/node": "^
|
|
30
|
-
"ava": "^5.3.1",
|
|
27
|
+
"@sindresorhus/tsconfig": "^8.0.1",
|
|
28
|
+
"@types/benchmark": "^2.1.5",
|
|
29
|
+
"@types/node": "^25.6.0",
|
|
31
30
|
"benchmark": "^2.1.4",
|
|
32
|
-
"del-cli": "^
|
|
33
|
-
"delay": "^
|
|
31
|
+
"del-cli": "^6.0.0",
|
|
32
|
+
"delay": "^6.0.0",
|
|
34
33
|
"in-range": "^3.0.0",
|
|
35
|
-
"p-defer": "^4.0.
|
|
36
|
-
"random-int": "^3.
|
|
37
|
-
"time-span": "^5.
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"typescript": "^5.
|
|
41
|
-
"xo": "^
|
|
42
|
-
},
|
|
43
|
-
"ava": {
|
|
44
|
-
"files": [
|
|
45
|
-
"test/**"
|
|
46
|
-
],
|
|
47
|
-
"extensions": {
|
|
48
|
-
"ts": "module"
|
|
49
|
-
},
|
|
50
|
-
"nodeArguments": [
|
|
51
|
-
"--loader=ts-node/esm"
|
|
52
|
-
]
|
|
34
|
+
"p-defer": "^4.0.1",
|
|
35
|
+
"random-int": "^3.1.0",
|
|
36
|
+
"time-span": "^5.1.0",
|
|
37
|
+
"tsd": "^0.33.0",
|
|
38
|
+
"tsx": "^4.20.5",
|
|
39
|
+
"typescript": "^5.9.2",
|
|
40
|
+
"xo": "^1.2.2"
|
|
53
41
|
},
|
|
54
42
|
"xo": {
|
|
55
43
|
"rules": {
|
|
56
44
|
"@typescript-eslint/member-ordering": "off",
|
|
57
45
|
"@typescript-eslint/no-floating-promises": "off",
|
|
58
|
-
"@typescript-eslint/no-
|
|
46
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
47
|
+
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
48
|
+
"@typescript-eslint/no-unsafe-return": "off",
|
|
49
|
+
"@typescript-eslint/no-unsafe-argument": "off",
|
|
50
|
+
"@typescript-eslint/prefer-promise-reject-errors": "off",
|
|
51
|
+
"ava/no-import-test-files": "off"
|
|
59
52
|
}
|
|
60
53
|
},
|
|
61
54
|
"homepage": "https://github.com/etienne-martin/common.js#readme",
|