@common.js/p-queue 7.4.1 → 8.0.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 +4 -8
- package/dist/index.js +272 -223
- package/dist/options.d.ts +9 -9
- package/dist/priority-queue.d.ts +4 -4
- package/dist/priority-queue.js +38 -17
- package/dist/queue.d.ts +3 -3
- package/package.json +19 -18
package/README.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
The [p-queue](https://www.npmjs.com/package/p-queue) package exported as CommonJS modules.
|
|
4
4
|
|
|
5
|
-
Exported from [p-queue@
|
|
5
|
+
Exported from [p-queue@8.0.1](https://www.npmjs.com/package/p-queue/v/8.0.1) using https://github.com/etienne-martin/common.js.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
|
-
import { Queue, RunFunction } from './queue.js';
|
|
2
|
+
import { type Queue, type RunFunction } from './queue.js';
|
|
3
3
|
import PriorityQueue from './priority-queue.js';
|
|
4
|
-
import { QueueAddOptions, Options, TaskOptions } from './options.js';
|
|
4
|
+
import { type QueueAddOptions, type Options, type TaskOptions } from './options.js';
|
|
5
5
|
type Task<TaskResultType> = ((options: TaskOptions) => PromiseLike<TaskResultType>) | ((options: TaskOptions) => TaskResultType);
|
|
6
|
-
/**
|
|
7
|
-
The error thrown by `queue.add()` when a job is aborted before it is run. See `signal`.
|
|
8
|
-
*/
|
|
9
|
-
export declare class AbortError extends Error {
|
|
10
|
-
}
|
|
11
6
|
type EventName = 'active' | 'idle' | 'empty' | 'add' | 'next' | 'completed' | 'error';
|
|
12
7
|
/**
|
|
13
8
|
Promise queue with concurrency control.
|
|
@@ -90,4 +85,5 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
|
|
|
90
85
|
*/
|
|
91
86
|
get isPaused(): boolean;
|
|
92
87
|
}
|
|
93
|
-
export { Queue
|
|
88
|
+
export type { Queue } from './queue.js';
|
|
89
|
+
export { type QueueAddOptions, type Options } from './options.js';
|
package/dist/index.js
CHANGED
|
@@ -2,18 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
AbortError: function() {
|
|
13
|
-
return AbortError;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return PQueue;
|
|
17
9
|
}
|
|
18
10
|
});
|
|
19
11
|
var _eventemitter3 = require("eventemitter3");
|
|
@@ -54,38 +46,84 @@ function _asyncToGenerator(fn) {
|
|
|
54
46
|
});
|
|
55
47
|
};
|
|
56
48
|
}
|
|
49
|
+
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
50
|
+
if (privateCollection.has(obj)) {
|
|
51
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
55
|
+
if (descriptor.get) {
|
|
56
|
+
return descriptor.get.call(receiver);
|
|
57
|
+
}
|
|
58
|
+
return descriptor.value;
|
|
59
|
+
}
|
|
60
|
+
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
61
|
+
if (descriptor.set) {
|
|
62
|
+
descriptor.set.call(receiver, value);
|
|
63
|
+
} else {
|
|
64
|
+
if (!descriptor.writable) {
|
|
65
|
+
throw new TypeError("attempted to set read only private field");
|
|
66
|
+
}
|
|
67
|
+
descriptor.value = value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function _classApplyDescriptorUpdate(receiver, descriptor) {
|
|
71
|
+
if (descriptor.set) {
|
|
72
|
+
if (!("__destrWrapper" in descriptor)) {
|
|
73
|
+
descriptor.__destrWrapper = {
|
|
74
|
+
set value (v){
|
|
75
|
+
descriptor.set.call(receiver, v);
|
|
76
|
+
},
|
|
77
|
+
get value () {
|
|
78
|
+
return descriptor.get.call(receiver);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return descriptor.__destrWrapper;
|
|
83
|
+
} else {
|
|
84
|
+
if (!descriptor.writable) {
|
|
85
|
+
throw new TypeError("attempted to set read only private field");
|
|
86
|
+
}
|
|
87
|
+
return descriptor;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
57
90
|
function _classCallCheck(instance, Constructor) {
|
|
58
91
|
if (!(instance instanceof Constructor)) {
|
|
59
92
|
throw new TypeError("Cannot call a class as a function");
|
|
60
93
|
}
|
|
61
94
|
}
|
|
62
|
-
function
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
if (typeof Proxy === "function") return true;
|
|
66
|
-
try {
|
|
67
|
-
Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
|
|
68
|
-
return true;
|
|
69
|
-
} catch (e) {
|
|
70
|
-
return false;
|
|
95
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
96
|
+
if (!privateMap.has(receiver)) {
|
|
97
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
71
98
|
}
|
|
99
|
+
return privateMap.get(receiver);
|
|
72
100
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
function _classPrivateFieldGet(receiver, privateMap) {
|
|
102
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
103
|
+
return _classApplyDescriptorGet(receiver, descriptor);
|
|
104
|
+
}
|
|
105
|
+
function _classPrivateFieldInit(obj, privateMap, value) {
|
|
106
|
+
_checkPrivateRedeclaration(obj, privateMap);
|
|
107
|
+
privateMap.set(obj, value);
|
|
108
|
+
}
|
|
109
|
+
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
110
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
111
|
+
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
function _classPrivateFieldUpdate(receiver, privateMap) {
|
|
115
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "update");
|
|
116
|
+
return _classApplyDescriptorUpdate(receiver, descriptor);
|
|
117
|
+
}
|
|
118
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) {
|
|
119
|
+
if (!privateSet.has(receiver)) {
|
|
120
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
87
121
|
}
|
|
88
|
-
return
|
|
122
|
+
return fn;
|
|
123
|
+
}
|
|
124
|
+
function _classPrivateMethodInit(obj, privateSet) {
|
|
125
|
+
_checkPrivateRedeclaration(obj, privateSet);
|
|
126
|
+
privateSet.add(obj);
|
|
89
127
|
}
|
|
90
128
|
function _defineProperties(target, props) {
|
|
91
129
|
for(var i = 0; i < props.length; i++){
|
|
@@ -184,9 +222,6 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
184
222
|
}
|
|
185
223
|
return newObj;
|
|
186
224
|
}
|
|
187
|
-
function _isNativeFunction(fn) {
|
|
188
|
-
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
189
|
-
}
|
|
190
225
|
function _objectSpread(target) {
|
|
191
226
|
for(var i = 1; i < arguments.length; i++){
|
|
192
227
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -219,32 +254,6 @@ var _typeof = function(obj) {
|
|
|
219
254
|
"@swc/helpers - typeof";
|
|
220
255
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
221
256
|
};
|
|
222
|
-
function _wrapNativeSuper(Class) {
|
|
223
|
-
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
224
|
-
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
225
|
-
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
226
|
-
if (typeof Class !== "function") {
|
|
227
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
228
|
-
}
|
|
229
|
-
if (typeof _cache !== "undefined") {
|
|
230
|
-
if (_cache.has(Class)) return _cache.get(Class);
|
|
231
|
-
_cache.set(Class, Wrapper);
|
|
232
|
-
}
|
|
233
|
-
function Wrapper() {
|
|
234
|
-
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
235
|
-
}
|
|
236
|
-
Wrapper.prototype = Object.create(Class.prototype, {
|
|
237
|
-
constructor: {
|
|
238
|
-
value: Wrapper,
|
|
239
|
-
enumerable: false,
|
|
240
|
-
writable: true,
|
|
241
|
-
configurable: true
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
return _setPrototypeOf(Wrapper, Class);
|
|
245
|
-
};
|
|
246
|
-
return _wrapNativeSuper(Class);
|
|
247
|
-
}
|
|
248
257
|
function _isNativeReflectConstruct() {
|
|
249
258
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
250
259
|
if (Reflect.construct.sham) return false;
|
|
@@ -287,10 +296,10 @@ var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
|
287
296
|
return this;
|
|
288
297
|
}), g;
|
|
289
298
|
function verb(n) {
|
|
290
|
-
return function(
|
|
299
|
+
return function(v1) {
|
|
291
300
|
return step([
|
|
292
301
|
n,
|
|
293
|
-
|
|
302
|
+
v1
|
|
294
303
|
]);
|
|
295
304
|
};
|
|
296
305
|
}
|
|
@@ -364,65 +373,99 @@ var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
|
364
373
|
};
|
|
365
374
|
}
|
|
366
375
|
};
|
|
367
|
-
var
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
};
|
|
373
|
-
var __classPrivateFieldGet = (void 0) && (void 0).__classPrivateFieldGet || function(receiver, state, kind, f) {
|
|
374
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
375
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
376
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
377
|
-
};
|
|
378
|
-
var _PQueue_instances, _PQueue_carryoverConcurrencyCount, _PQueue_isIntervalIgnored, _PQueue_intervalCount, _PQueue_intervalCap, _PQueue_interval, _PQueue_intervalEnd, _PQueue_intervalId, _PQueue_timeoutId, _PQueue_queue, _PQueue_queueClass, _PQueue_pending, _PQueue_concurrency, _PQueue_isPaused, _PQueue_throwOnTimeout, _PQueue_doesIntervalAllowAnother_get, _PQueue_doesConcurrentAllowAnother_get, _PQueue_next, _PQueue_onResumeInterval, _PQueue_isIntervalPaused_get, _PQueue_tryToStartAnother, _PQueue_initializeIntervalIfNeeded, _PQueue_onInterval, _PQueue_processQueue, _PQueue_throwOnAbort, _PQueue_onEvent;
|
|
379
|
-
var AbortError = /*#__PURE__*/ function(Error1) {
|
|
380
|
-
"use strict";
|
|
381
|
-
_inherits(AbortError, Error1);
|
|
382
|
-
var _super = _createSuper(AbortError);
|
|
383
|
-
function AbortError() {
|
|
384
|
-
_classCallCheck(this, AbortError);
|
|
385
|
-
return _super.apply(this, arguments);
|
|
386
|
-
}
|
|
387
|
-
return AbortError;
|
|
388
|
-
}(_wrapNativeSuper(Error));
|
|
389
|
-
/**
|
|
390
|
-
Promise queue with concurrency control.
|
|
391
|
-
*/ var PQueue = /*#__PURE__*/ function(EventEmitter) {
|
|
376
|
+
var _carryoverConcurrencyCount = /*#__PURE__*/ new WeakMap(), _isIntervalIgnored = /*#__PURE__*/ new WeakMap(), _intervalCount = /*#__PURE__*/ new WeakMap(), _intervalCap = /*#__PURE__*/ new WeakMap(), _interval = /*#__PURE__*/ new WeakMap(), _intervalEnd = /*#__PURE__*/ new WeakMap(), _intervalId = /*#__PURE__*/ new WeakMap(), _timeoutId = /*#__PURE__*/ new WeakMap(), _queue = /*#__PURE__*/ new WeakMap(), _queueClass = /*#__PURE__*/ new WeakMap(), _pending = /*#__PURE__*/ new WeakMap(), // The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
377
|
+
_concurrency = /*#__PURE__*/ new WeakMap(), _isPaused = /*#__PURE__*/ new WeakMap(), _throwOnTimeout = /*#__PURE__*/ new WeakMap(), _doesIntervalAllowAnother = /*#__PURE__*/ new WeakMap(), _doesConcurrentAllowAnother = /*#__PURE__*/ new WeakMap(), _next = /*#__PURE__*/ new WeakSet(), _onResumeInterval = /*#__PURE__*/ new WeakSet(), _isIntervalPaused = /*#__PURE__*/ new WeakMap(), _tryToStartAnother = /*#__PURE__*/ new WeakSet(), _initializeIntervalIfNeeded = /*#__PURE__*/ new WeakSet(), _onInterval = /*#__PURE__*/ new WeakSet(), /**
|
|
378
|
+
Executes all queued functions until it reaches the limit.
|
|
379
|
+
*/ _processQueue = /*#__PURE__*/ new WeakSet(), _throwOnAbort = /*#__PURE__*/ new WeakSet(), _onEvent = /*#__PURE__*/ new WeakSet();
|
|
380
|
+
var PQueue = /*#__PURE__*/ function(EventEmitter) {
|
|
392
381
|
"use strict";
|
|
393
382
|
_inherits(PQueue, EventEmitter);
|
|
394
383
|
var _super = _createSuper(PQueue);
|
|
395
384
|
function PQueue(options) {
|
|
396
385
|
_classCallCheck(this, PQueue);
|
|
397
386
|
var _this;
|
|
398
|
-
var _a, _b, _c, _d;
|
|
399
387
|
_this = _super.call(this);
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
388
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _doesIntervalAllowAnother, {
|
|
389
|
+
get: get_doesIntervalAllowAnother,
|
|
390
|
+
set: void 0
|
|
391
|
+
});
|
|
392
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _doesConcurrentAllowAnother, {
|
|
393
|
+
get: get_doesConcurrentAllowAnother,
|
|
394
|
+
set: void 0
|
|
395
|
+
});
|
|
396
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _next);
|
|
397
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _onResumeInterval);
|
|
398
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _isIntervalPaused, {
|
|
399
|
+
get: get_isIntervalPaused,
|
|
400
|
+
set: void 0
|
|
401
|
+
});
|
|
402
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _tryToStartAnother);
|
|
403
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _initializeIntervalIfNeeded);
|
|
404
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _onInterval);
|
|
405
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _processQueue);
|
|
406
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _throwOnAbort);
|
|
407
|
+
_classPrivateMethodInit(_assertThisInitialized(_this), _onEvent);
|
|
408
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _carryoverConcurrencyCount, {
|
|
409
|
+
writable: true,
|
|
410
|
+
value: void 0
|
|
411
|
+
});
|
|
412
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _isIntervalIgnored, {
|
|
423
413
|
writable: true,
|
|
424
414
|
value: void 0
|
|
425
415
|
});
|
|
416
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _intervalCount, {
|
|
417
|
+
writable: true,
|
|
418
|
+
value: 0
|
|
419
|
+
});
|
|
420
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _intervalCap, {
|
|
421
|
+
writable: true,
|
|
422
|
+
value: void 0
|
|
423
|
+
});
|
|
424
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _interval, {
|
|
425
|
+
writable: true,
|
|
426
|
+
value: void 0
|
|
427
|
+
});
|
|
428
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _intervalEnd, {
|
|
429
|
+
writable: true,
|
|
430
|
+
value: 0
|
|
431
|
+
});
|
|
432
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _intervalId, {
|
|
433
|
+
writable: true,
|
|
434
|
+
value: void 0
|
|
435
|
+
});
|
|
436
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _timeoutId, {
|
|
437
|
+
writable: true,
|
|
438
|
+
value: void 0
|
|
439
|
+
});
|
|
440
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _queue, {
|
|
441
|
+
writable: true,
|
|
442
|
+
value: void 0
|
|
443
|
+
});
|
|
444
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _queueClass, {
|
|
445
|
+
writable: true,
|
|
446
|
+
value: void 0
|
|
447
|
+
});
|
|
448
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _pending, {
|
|
449
|
+
writable: true,
|
|
450
|
+
value: 0
|
|
451
|
+
});
|
|
452
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _concurrency, {
|
|
453
|
+
writable: true,
|
|
454
|
+
value: void 0
|
|
455
|
+
});
|
|
456
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _isPaused, {
|
|
457
|
+
writable: true,
|
|
458
|
+
value: void 0
|
|
459
|
+
});
|
|
460
|
+
_classPrivateFieldInit(_assertThisInitialized(_this), _throwOnTimeout, {
|
|
461
|
+
writable: true,
|
|
462
|
+
value: void 0
|
|
463
|
+
});
|
|
464
|
+
/**
|
|
465
|
+
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
466
|
+
|
|
467
|
+
Applies to each future operation.
|
|
468
|
+
*/ _defineProperty(_assertThisInitialized(_this), "timeout", void 0);
|
|
426
469
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
427
470
|
options = _objectSpread({
|
|
428
471
|
carryoverConcurrencyCount: false,
|
|
@@ -433,35 +476,39 @@ Promise queue with concurrency control.
|
|
|
433
476
|
queueClass: _priorityQueueJs.default
|
|
434
477
|
}, options);
|
|
435
478
|
if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
|
|
436
|
-
|
|
479
|
+
var ref;
|
|
480
|
+
var ref1;
|
|
481
|
+
throw new TypeError("Expected `intervalCap` to be a number from 1 and up, got `".concat((ref1 = (ref = options.intervalCap) === null || ref === void 0 ? void 0 : ref.toString()) !== null && ref1 !== void 0 ? ref1 : "", "` (").concat(_typeof(options.intervalCap), ")"));
|
|
437
482
|
}
|
|
438
483
|
if (options.interval === undefined || !(Number.isFinite(options.interval) && options.interval >= 0)) {
|
|
439
|
-
|
|
484
|
+
var ref2;
|
|
485
|
+
var ref3;
|
|
486
|
+
throw new TypeError("Expected `interval` to be a finite number >= 0, got `".concat((ref3 = (ref2 = options.interval) === null || ref2 === void 0 ? void 0 : ref2.toString()) !== null && ref3 !== void 0 ? ref3 : "", "` (").concat(_typeof(options.interval), ")"));
|
|
440
487
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
488
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _carryoverConcurrencyCount, options.carryoverConcurrencyCount);
|
|
489
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _isIntervalIgnored, options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0);
|
|
490
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _intervalCap, options.intervalCap);
|
|
491
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _interval, options.interval);
|
|
492
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _queue, new options.queueClass());
|
|
493
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _queueClass, options.queueClass);
|
|
447
494
|
_this.concurrency = options.concurrency;
|
|
448
495
|
_this.timeout = options.timeout;
|
|
449
|
-
|
|
450
|
-
|
|
496
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _throwOnTimeout, options.throwOnTimeout === true);
|
|
497
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _isPaused, options.autoStart === false);
|
|
451
498
|
return _this;
|
|
452
499
|
}
|
|
453
500
|
_createClass(PQueue, [
|
|
454
501
|
{
|
|
455
502
|
key: "concurrency",
|
|
456
503
|
get: function get() {
|
|
457
|
-
return
|
|
504
|
+
return _classPrivateFieldGet(this, _concurrency);
|
|
458
505
|
},
|
|
459
506
|
set: function set(newConcurrency) {
|
|
460
507
|
if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) {
|
|
461
508
|
throw new TypeError("Expected `concurrency` to be a number from 1 and up, got `".concat(newConcurrency, "` (").concat(typeof newConcurrency === "undefined" ? "undefined" : _typeof(newConcurrency), ")"));
|
|
462
509
|
}
|
|
463
|
-
|
|
464
|
-
|
|
510
|
+
_classPrivateFieldSet(this, _concurrency, newConcurrency);
|
|
511
|
+
_classPrivateMethodGet(this, _processQueue, processQueue).call(this);
|
|
465
512
|
}
|
|
466
513
|
},
|
|
467
514
|
{
|
|
@@ -473,18 +520,18 @@ Promise queue with concurrency control.
|
|
|
473
520
|
return __generator(this, function(_state) {
|
|
474
521
|
options = _objectSpread({
|
|
475
522
|
timeout: _this.timeout,
|
|
476
|
-
throwOnTimeout:
|
|
523
|
+
throwOnTimeout: _classPrivateFieldGet(_this, _throwOnTimeout)
|
|
477
524
|
}, options);
|
|
478
525
|
return [
|
|
479
526
|
2,
|
|
480
527
|
new Promise(function(resolve, reject) {
|
|
481
|
-
|
|
482
|
-
var
|
|
528
|
+
_classPrivateFieldGet(_this, _queue).enqueue(/*#__PURE__*/ _asyncToGenerator(function() {
|
|
529
|
+
var ref, operation, result, error;
|
|
483
530
|
return __generator(this, function(_state) {
|
|
484
531
|
switch(_state.label){
|
|
485
532
|
case 0:
|
|
486
|
-
|
|
487
|
-
|
|
533
|
+
_classPrivateFieldUpdate(_this, _pending).value++;
|
|
534
|
+
_classPrivateFieldUpdate(_this, _intervalCount).value++;
|
|
488
535
|
_state.label = 1;
|
|
489
536
|
case 1:
|
|
490
537
|
_state.trys.push([
|
|
@@ -493,21 +540,19 @@ Promise queue with concurrency control.
|
|
|
493
540
|
4,
|
|
494
541
|
5
|
|
495
542
|
]);
|
|
496
|
-
|
|
497
|
-
if ((_a = options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
498
|
-
// TODO: Use ABORT_ERR code when targeting Node.js 16 (https://nodejs.org/docs/latest-v16.x/api/errors.html#abort_err)
|
|
499
|
-
throw new AbortError("The task was aborted.");
|
|
500
|
-
}
|
|
543
|
+
(ref = options.signal) === null || ref === void 0 ? void 0 : ref.throwIfAborted();
|
|
501
544
|
operation = function_({
|
|
502
545
|
signal: options.signal
|
|
503
546
|
});
|
|
504
547
|
if (options.timeout) {
|
|
505
|
-
operation = (0, _pTimeout.default)(Promise.resolve(operation),
|
|
548
|
+
operation = (0, _pTimeout.default)(Promise.resolve(operation), {
|
|
549
|
+
milliseconds: options.timeout
|
|
550
|
+
});
|
|
506
551
|
}
|
|
507
552
|
if (options.signal) {
|
|
508
553
|
operation = Promise.race([
|
|
509
554
|
operation,
|
|
510
|
-
|
|
555
|
+
_classPrivateMethodGet(_this, _throwOnAbort, throwOnAbort).call(_this, options.signal)
|
|
511
556
|
]);
|
|
512
557
|
}
|
|
513
558
|
return [
|
|
@@ -537,7 +582,7 @@ Promise queue with concurrency control.
|
|
|
537
582
|
5
|
|
538
583
|
];
|
|
539
584
|
case 4:
|
|
540
|
-
|
|
585
|
+
_classPrivateMethodGet(_this, _next, next).call(_this);
|
|
541
586
|
return [
|
|
542
587
|
7
|
|
543
588
|
];
|
|
@@ -549,7 +594,7 @@ Promise queue with concurrency control.
|
|
|
549
594
|
});
|
|
550
595
|
}), options);
|
|
551
596
|
_this.emit("add");
|
|
552
|
-
|
|
597
|
+
_classPrivateMethodGet(_this, _tryToStartAnother, tryToStartAnother).call(_this);
|
|
553
598
|
})
|
|
554
599
|
];
|
|
555
600
|
});
|
|
@@ -587,11 +632,11 @@ Promise queue with concurrency control.
|
|
|
587
632
|
Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
|
|
588
633
|
*/ key: "start",
|
|
589
634
|
value: function start() {
|
|
590
|
-
if (!
|
|
635
|
+
if (!_classPrivateFieldGet(this, _isPaused)) {
|
|
591
636
|
return this;
|
|
592
637
|
}
|
|
593
|
-
|
|
594
|
-
|
|
638
|
+
_classPrivateFieldSet(this, _isPaused, false);
|
|
639
|
+
_classPrivateMethodGet(this, _processQueue, processQueue).call(this);
|
|
595
640
|
return this;
|
|
596
641
|
}
|
|
597
642
|
},
|
|
@@ -600,7 +645,7 @@ Promise queue with concurrency control.
|
|
|
600
645
|
Put queue execution on hold.
|
|
601
646
|
*/ key: "pause",
|
|
602
647
|
value: function pause() {
|
|
603
|
-
|
|
648
|
+
_classPrivateFieldSet(this, _isPaused, true);
|
|
604
649
|
}
|
|
605
650
|
},
|
|
606
651
|
{
|
|
@@ -608,7 +653,7 @@ Promise queue with concurrency control.
|
|
|
608
653
|
Clear the queue.
|
|
609
654
|
*/ key: "clear",
|
|
610
655
|
value: function clear() {
|
|
611
|
-
|
|
656
|
+
_classPrivateFieldSet(this, _queue, new (_classPrivateFieldGet(this, _queueClass))());
|
|
612
657
|
}
|
|
613
658
|
},
|
|
614
659
|
{
|
|
@@ -624,14 +669,14 @@ Promise queue with concurrency control.
|
|
|
624
669
|
switch(_state.label){
|
|
625
670
|
case 0:
|
|
626
671
|
// Instantly resolve if the queue is empty
|
|
627
|
-
if (
|
|
672
|
+
if (_classPrivateFieldGet(_this, _queue).size === 0) {
|
|
628
673
|
return [
|
|
629
674
|
2
|
|
630
675
|
];
|
|
631
676
|
}
|
|
632
677
|
return [
|
|
633
678
|
4,
|
|
634
|
-
|
|
679
|
+
_classPrivateMethodGet(_this, _onEvent, onEvent).call(_this, "empty")
|
|
635
680
|
];
|
|
636
681
|
case 1:
|
|
637
682
|
_state.sent();
|
|
@@ -658,15 +703,15 @@ Promise queue with concurrency control.
|
|
|
658
703
|
switch(_state.label){
|
|
659
704
|
case 0:
|
|
660
705
|
// Instantly resolve if the queue is empty.
|
|
661
|
-
if (
|
|
706
|
+
if (_classPrivateFieldGet(_this, _queue).size < limit) {
|
|
662
707
|
return [
|
|
663
708
|
2
|
|
664
709
|
];
|
|
665
710
|
}
|
|
666
711
|
return [
|
|
667
712
|
4,
|
|
668
|
-
|
|
669
|
-
return
|
|
713
|
+
_classPrivateMethodGet(_this, _onEvent, onEvent).call(_this, "next", function() {
|
|
714
|
+
return _classPrivateFieldGet(_this, _queue).size < limit;
|
|
670
715
|
})
|
|
671
716
|
];
|
|
672
717
|
case 1:
|
|
@@ -692,14 +737,14 @@ Promise queue with concurrency control.
|
|
|
692
737
|
switch(_state.label){
|
|
693
738
|
case 0:
|
|
694
739
|
// Instantly resolve if none pending and if nothing else is queued
|
|
695
|
-
if (
|
|
740
|
+
if (_classPrivateFieldGet(_this, _pending) === 0 && _classPrivateFieldGet(_this, _queue).size === 0) {
|
|
696
741
|
return [
|
|
697
742
|
2
|
|
698
743
|
];
|
|
699
744
|
}
|
|
700
745
|
return [
|
|
701
746
|
4,
|
|
702
|
-
|
|
747
|
+
_classPrivateMethodGet(_this, _onEvent, onEvent).call(_this, "idle")
|
|
703
748
|
];
|
|
704
749
|
case 1:
|
|
705
750
|
_state.sent();
|
|
@@ -716,7 +761,7 @@ Promise queue with concurrency control.
|
|
|
716
761
|
get: /**
|
|
717
762
|
Size of the queue, the number of queued items waiting to run.
|
|
718
763
|
*/ function get() {
|
|
719
|
-
return
|
|
764
|
+
return _classPrivateFieldGet(this, _queue).size;
|
|
720
765
|
}
|
|
721
766
|
},
|
|
722
767
|
{
|
|
@@ -727,7 +772,7 @@ Promise queue with concurrency control.
|
|
|
727
772
|
*/ key: "sizeBy",
|
|
728
773
|
value: function sizeBy(options) {
|
|
729
774
|
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
730
|
-
return
|
|
775
|
+
return _classPrivateFieldGet(this, _queue).filter(options).length;
|
|
731
776
|
}
|
|
732
777
|
},
|
|
733
778
|
{
|
|
@@ -735,7 +780,7 @@ Promise queue with concurrency control.
|
|
|
735
780
|
get: /**
|
|
736
781
|
Number of running items (no longer in the queue).
|
|
737
782
|
*/ function get() {
|
|
738
|
-
return
|
|
783
|
+
return _classPrivateFieldGet(this, _pending);
|
|
739
784
|
}
|
|
740
785
|
},
|
|
741
786
|
{
|
|
@@ -743,104 +788,111 @@ Promise queue with concurrency control.
|
|
|
743
788
|
get: /**
|
|
744
789
|
Whether the queue is currently paused.
|
|
745
790
|
*/ function get() {
|
|
746
|
-
return
|
|
791
|
+
return _classPrivateFieldGet(this, _isPaused);
|
|
747
792
|
}
|
|
748
793
|
}
|
|
749
794
|
]);
|
|
750
795
|
return PQueue;
|
|
751
796
|
}(_eventemitter3.EventEmitter);
|
|
752
|
-
|
|
753
|
-
return
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
797
|
+
function get_doesIntervalAllowAnother() {
|
|
798
|
+
return _classPrivateFieldGet(this, _isIntervalIgnored) || _classPrivateFieldGet(this, _intervalCount) < _classPrivateFieldGet(this, _intervalCap);
|
|
799
|
+
}
|
|
800
|
+
function get_doesConcurrentAllowAnother() {
|
|
801
|
+
return _classPrivateFieldGet(this, _pending) < _classPrivateFieldGet(this, _concurrency);
|
|
802
|
+
}
|
|
803
|
+
function next() {
|
|
804
|
+
_classPrivateFieldUpdate(this, _pending).value--;
|
|
805
|
+
_classPrivateMethodGet(this, _tryToStartAnother, tryToStartAnother).call(this);
|
|
760
806
|
this.emit("next");
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
807
|
+
}
|
|
808
|
+
function onResumeInterval() {
|
|
809
|
+
_classPrivateMethodGet(this, _onInterval, onInterval).call(this);
|
|
810
|
+
_classPrivateMethodGet(this, _initializeIntervalIfNeeded, initializeIntervalIfNeeded).call(this);
|
|
811
|
+
_classPrivateFieldSet(this, _timeoutId, undefined);
|
|
812
|
+
}
|
|
813
|
+
function get_isIntervalPaused() {
|
|
766
814
|
var _this = this;
|
|
767
815
|
var now = Date.now();
|
|
768
|
-
if (
|
|
769
|
-
var delay =
|
|
816
|
+
if (_classPrivateFieldGet(this, _intervalId) === undefined) {
|
|
817
|
+
var delay = _classPrivateFieldGet(this, _intervalEnd) - now;
|
|
770
818
|
if (delay < 0) {
|
|
771
|
-
|
|
772
|
-
// We don't need to resume it here because it will be resumed on line 160
|
|
773
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, __classPrivateFieldGet(this, _PQueue_carryoverConcurrencyCount, "f") ? __classPrivateFieldGet(this, _PQueue_pending, "f") : 0, "f");
|
|
819
|
+
_classPrivateFieldSet(this, _intervalCount, _classPrivateFieldGet(this, _carryoverConcurrencyCount) ? _classPrivateFieldGet(this, _pending) : 0);
|
|
774
820
|
} else {
|
|
775
821
|
// Act as the interval is pending
|
|
776
|
-
if (
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
}, delay)
|
|
822
|
+
if (_classPrivateFieldGet(this, _timeoutId) === undefined) {
|
|
823
|
+
_classPrivateFieldSet(this, _timeoutId, setTimeout(function() {
|
|
824
|
+
_classPrivateMethodGet(_this, _onResumeInterval, onResumeInterval).call(_this);
|
|
825
|
+
}, delay));
|
|
780
826
|
}
|
|
781
827
|
return true;
|
|
782
828
|
}
|
|
783
829
|
}
|
|
784
830
|
return false;
|
|
785
|
-
}
|
|
786
|
-
|
|
831
|
+
}
|
|
832
|
+
function tryToStartAnother() {
|
|
833
|
+
if (_classPrivateFieldGet(this, _queue).size === 0) {
|
|
787
834
|
// We can clear the interval ("pause")
|
|
788
835
|
// Because we can redo it later ("resume")
|
|
789
|
-
if (
|
|
790
|
-
clearInterval(
|
|
836
|
+
if (_classPrivateFieldGet(this, _intervalId)) {
|
|
837
|
+
clearInterval(_classPrivateFieldGet(this, _intervalId));
|
|
791
838
|
}
|
|
792
|
-
|
|
839
|
+
_classPrivateFieldSet(this, _intervalId, undefined);
|
|
793
840
|
this.emit("empty");
|
|
794
|
-
if (
|
|
841
|
+
if (_classPrivateFieldGet(this, _pending) === 0) {
|
|
795
842
|
this.emit("idle");
|
|
796
843
|
}
|
|
797
844
|
return false;
|
|
798
845
|
}
|
|
799
|
-
if (!
|
|
800
|
-
var canInitializeInterval = !
|
|
801
|
-
if (
|
|
802
|
-
var job =
|
|
846
|
+
if (!_classPrivateFieldGet(this, _isPaused)) {
|
|
847
|
+
var canInitializeInterval = !_classPrivateFieldGet(this, _isIntervalPaused);
|
|
848
|
+
if (_classPrivateFieldGet(this, _doesIntervalAllowAnother) && _classPrivateFieldGet(this, _doesConcurrentAllowAnother)) {
|
|
849
|
+
var job = _classPrivateFieldGet(this, _queue).dequeue();
|
|
803
850
|
if (!job) {
|
|
804
851
|
return false;
|
|
805
852
|
}
|
|
806
853
|
this.emit("active");
|
|
807
854
|
job();
|
|
808
855
|
if (canInitializeInterval) {
|
|
809
|
-
|
|
856
|
+
_classPrivateMethodGet(this, _initializeIntervalIfNeeded, initializeIntervalIfNeeded).call(this);
|
|
810
857
|
}
|
|
811
858
|
return true;
|
|
812
859
|
}
|
|
813
860
|
}
|
|
814
861
|
return false;
|
|
815
|
-
}
|
|
862
|
+
}
|
|
863
|
+
function initializeIntervalIfNeeded() {
|
|
816
864
|
var _this = this;
|
|
817
|
-
if (
|
|
865
|
+
if (_classPrivateFieldGet(this, _isIntervalIgnored) || _classPrivateFieldGet(this, _intervalId) !== undefined) {
|
|
818
866
|
return;
|
|
819
867
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
},
|
|
823
|
-
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
868
|
+
_classPrivateFieldSet(this, _intervalId, setInterval(function() {
|
|
869
|
+
_classPrivateMethodGet(_this, _onInterval, onInterval).call(_this);
|
|
870
|
+
}, _classPrivateFieldGet(this, _interval)));
|
|
871
|
+
_classPrivateFieldSet(this, _intervalEnd, Date.now() + _classPrivateFieldGet(this, _interval));
|
|
872
|
+
}
|
|
873
|
+
function onInterval() {
|
|
874
|
+
if (_classPrivateFieldGet(this, _intervalCount) === 0 && _classPrivateFieldGet(this, _pending) === 0 && _classPrivateFieldGet(this, _intervalId)) {
|
|
875
|
+
clearInterval(_classPrivateFieldGet(this, _intervalId));
|
|
876
|
+
_classPrivateFieldSet(this, _intervalId, undefined);
|
|
828
877
|
}
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
}
|
|
878
|
+
_classPrivateFieldSet(this, _intervalCount, _classPrivateFieldGet(this, _carryoverConcurrencyCount) ? _classPrivateFieldGet(this, _pending) : 0);
|
|
879
|
+
_classPrivateMethodGet(this, _processQueue, processQueue).call(this);
|
|
880
|
+
}
|
|
881
|
+
function processQueue() {
|
|
832
882
|
// eslint-disable-next-line no-empty
|
|
833
|
-
while(
|
|
834
|
-
}
|
|
835
|
-
|
|
883
|
+
while(_classPrivateMethodGet(this, _tryToStartAnother, tryToStartAnother).call(this)){}
|
|
884
|
+
}
|
|
885
|
+
function throwOnAbort(signal) {
|
|
886
|
+
return _throwOnAbort1.apply(this, arguments);
|
|
887
|
+
}
|
|
888
|
+
function _throwOnAbort1() {
|
|
889
|
+
_throwOnAbort1 = _asyncToGenerator(function(signal) {
|
|
836
890
|
return __generator(this, function(_state) {
|
|
837
891
|
return [
|
|
838
892
|
2,
|
|
839
893
|
new Promise(function(_resolve, reject) {
|
|
840
894
|
signal.addEventListener("abort", function() {
|
|
841
|
-
|
|
842
|
-
// TODO: Use ABORT_ERR code when targeting Node.js 16 (https://nodejs.org/docs/latest-v16.x/api/errors.html#abort_err)
|
|
843
|
-
reject(new AbortError("The task was aborted."));
|
|
895
|
+
reject(signal.reason);
|
|
844
896
|
}, {
|
|
845
897
|
once: true
|
|
846
898
|
});
|
|
@@ -848,12 +900,13 @@ _PQueue_carryoverConcurrencyCount = new WeakMap(), _PQueue_isIntervalIgnored = n
|
|
|
848
900
|
];
|
|
849
901
|
});
|
|
850
902
|
});
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
return
|
|
855
|
-
}
|
|
856
|
-
|
|
903
|
+
return _throwOnAbort1.apply(this, arguments);
|
|
904
|
+
}
|
|
905
|
+
function onEvent(event, filter) {
|
|
906
|
+
return _onEvent1.apply(this, arguments);
|
|
907
|
+
}
|
|
908
|
+
function _onEvent1() {
|
|
909
|
+
_onEvent1 = _asyncToGenerator(function(event, filter) {
|
|
857
910
|
var _this;
|
|
858
911
|
return __generator(this, function(_state) {
|
|
859
912
|
_this = this;
|
|
@@ -872,9 +925,5 @@ _PQueue_carryoverConcurrencyCount = new WeakMap(), _PQueue_isIntervalIgnored = n
|
|
|
872
925
|
];
|
|
873
926
|
});
|
|
874
927
|
});
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}
|
|
878
|
-
return _PQueue_onEvent;
|
|
879
|
-
}();
|
|
880
|
-
var _default = PQueue;
|
|
928
|
+
return _onEvent1.apply(this, arguments);
|
|
929
|
+
}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Queue, RunFunction } from './queue.js';
|
|
2
|
-
|
|
1
|
+
import { type Queue, type RunFunction } from './queue.js';
|
|
2
|
+
type TimeoutOptions = {
|
|
3
3
|
/**
|
|
4
4
|
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
5
5
|
*/
|
|
@@ -10,8 +10,8 @@ interface TimeoutOptions {
|
|
|
10
10
|
@default false
|
|
11
11
|
*/
|
|
12
12
|
throwOnTimeout?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export
|
|
13
|
+
};
|
|
14
|
+
export type Options<QueueType extends Queue<RunFunction, QueueOptions>, QueueOptions extends QueueAddOptions> = {
|
|
15
15
|
/**
|
|
16
16
|
Concurrency limit.
|
|
17
17
|
|
|
@@ -52,16 +52,16 @@ export interface Options<QueueType extends Queue<RunFunction, QueueOptions>, Que
|
|
|
52
52
|
@default false
|
|
53
53
|
*/
|
|
54
54
|
readonly carryoverConcurrencyCount?: boolean;
|
|
55
|
-
}
|
|
56
|
-
export
|
|
55
|
+
} & TimeoutOptions;
|
|
56
|
+
export type QueueAddOptions = {
|
|
57
57
|
/**
|
|
58
58
|
Priority of operation. Operations with greater priority will be scheduled first.
|
|
59
59
|
|
|
60
60
|
@default 0
|
|
61
61
|
*/
|
|
62
62
|
readonly priority?: number;
|
|
63
|
-
}
|
|
64
|
-
export
|
|
63
|
+
} & TaskOptions & TimeoutOptions;
|
|
64
|
+
export type TaskOptions = {
|
|
65
65
|
/**
|
|
66
66
|
[`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
67
|
|
|
@@ -98,5 +98,5 @@ export interface TaskOptions {
|
|
|
98
98
|
```
|
|
99
99
|
*/
|
|
100
100
|
readonly signal?: AbortSignal;
|
|
101
|
-
}
|
|
101
|
+
};
|
|
102
102
|
export {};
|
package/dist/priority-queue.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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;
|
package/dist/priority-queue.js
CHANGED
|
@@ -5,15 +5,40 @@ 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 _checkPrivateRedeclaration(obj, privateCollection) {
|
|
13
|
+
if (privateCollection.has(obj)) {
|
|
14
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
18
|
+
if (descriptor.get) {
|
|
19
|
+
return descriptor.get.call(receiver);
|
|
20
|
+
}
|
|
21
|
+
return descriptor.value;
|
|
22
|
+
}
|
|
12
23
|
function _classCallCheck(instance, Constructor) {
|
|
13
24
|
if (!(instance instanceof Constructor)) {
|
|
14
25
|
throw new TypeError("Cannot call a class as a function");
|
|
15
26
|
}
|
|
16
27
|
}
|
|
28
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
29
|
+
if (!privateMap.has(receiver)) {
|
|
30
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
31
|
+
}
|
|
32
|
+
return privateMap.get(receiver);
|
|
33
|
+
}
|
|
34
|
+
function _classPrivateFieldGet(receiver, privateMap) {
|
|
35
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
36
|
+
return _classApplyDescriptorGet(receiver, descriptor);
|
|
37
|
+
}
|
|
38
|
+
function _classPrivateFieldInit(obj, privateMap, value) {
|
|
39
|
+
_checkPrivateRedeclaration(obj, privateMap);
|
|
40
|
+
privateMap.set(obj, value);
|
|
41
|
+
}
|
|
17
42
|
function _defineProperties(target, props) {
|
|
18
43
|
for(var i = 0; i < props.length; i++){
|
|
19
44
|
var descriptor = props[i];
|
|
@@ -61,17 +86,15 @@ function _objectSpread(target) {
|
|
|
61
86
|
}
|
|
62
87
|
return target;
|
|
63
88
|
}
|
|
64
|
-
var
|
|
65
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
66
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
67
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
68
|
-
};
|
|
69
|
-
var _PriorityQueue_queue;
|
|
89
|
+
var _queue = /*#__PURE__*/ new WeakMap();
|
|
70
90
|
var PriorityQueue = /*#__PURE__*/ function() {
|
|
71
91
|
"use strict";
|
|
72
92
|
function PriorityQueue() {
|
|
73
93
|
_classCallCheck(this, PriorityQueue);
|
|
74
|
-
|
|
94
|
+
_classPrivateFieldInit(this, _queue, {
|
|
95
|
+
writable: true,
|
|
96
|
+
value: []
|
|
97
|
+
});
|
|
75
98
|
}
|
|
76
99
|
_createClass(PriorityQueue, [
|
|
77
100
|
{
|
|
@@ -84,27 +107,27 @@ var PriorityQueue = /*#__PURE__*/ function() {
|
|
|
84
107
|
priority: options.priority,
|
|
85
108
|
run: run
|
|
86
109
|
};
|
|
87
|
-
if (this.size &&
|
|
88
|
-
|
|
110
|
+
if (this.size && _classPrivateFieldGet(this, _queue)[this.size - 1].priority >= options.priority) {
|
|
111
|
+
_classPrivateFieldGet(this, _queue).push(element);
|
|
89
112
|
return;
|
|
90
113
|
}
|
|
91
|
-
var index = (0, _lowerBoundJs.default)(
|
|
114
|
+
var index = (0, _lowerBoundJs.default)(_classPrivateFieldGet(this, _queue), element, function(a, b) {
|
|
92
115
|
return b.priority - a.priority;
|
|
93
116
|
});
|
|
94
|
-
|
|
117
|
+
_classPrivateFieldGet(this, _queue).splice(index, 0, element);
|
|
95
118
|
}
|
|
96
119
|
},
|
|
97
120
|
{
|
|
98
121
|
key: "dequeue",
|
|
99
122
|
value: function dequeue() {
|
|
100
|
-
var item =
|
|
123
|
+
var item = _classPrivateFieldGet(this, _queue).shift();
|
|
101
124
|
return item === null || item === void 0 ? void 0 : item.run;
|
|
102
125
|
}
|
|
103
126
|
},
|
|
104
127
|
{
|
|
105
128
|
key: "filter",
|
|
106
129
|
value: function filter(options) {
|
|
107
|
-
return
|
|
130
|
+
return _classPrivateFieldGet(this, _queue).filter(function(element) {
|
|
108
131
|
return element.priority === options.priority;
|
|
109
132
|
}).map(function(element) {
|
|
110
133
|
return element.run;
|
|
@@ -114,11 +137,9 @@ var PriorityQueue = /*#__PURE__*/ function() {
|
|
|
114
137
|
{
|
|
115
138
|
key: "size",
|
|
116
139
|
get: function get() {
|
|
117
|
-
return
|
|
140
|
+
return _classPrivateFieldGet(this, _queue).length;
|
|
118
141
|
}
|
|
119
142
|
}
|
|
120
143
|
]);
|
|
121
144
|
return PriorityQueue;
|
|
122
145
|
}();
|
|
123
|
-
_PriorityQueue_queue = new WeakMap();
|
|
124
|
-
var _default = PriorityQueue;
|
package/dist/queue.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common.js/p-queue",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.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": ">=18"
|
|
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 && ava && 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
23
|
"eventemitter3": "^5.0.1",
|
|
24
|
-
"@common.js/p-timeout": "^
|
|
24
|
+
"@common.js/p-timeout": "^6.1.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@sindresorhus/tsconfig": "^
|
|
28
|
-
"@types/benchmark": "^2.1.
|
|
29
|
-
"@types/node": "^
|
|
27
|
+
"@sindresorhus/tsconfig": "^5.0.0",
|
|
28
|
+
"@types/benchmark": "^2.1.5",
|
|
29
|
+
"@types/node": "^20.10.4",
|
|
30
30
|
"ava": "^5.3.1",
|
|
31
31
|
"benchmark": "^2.1.4",
|
|
32
|
-
"del-cli": "^5.
|
|
33
|
-
"delay": "^
|
|
32
|
+
"del-cli": "^5.1.0",
|
|
33
|
+
"delay": "^6.0.0",
|
|
34
34
|
"in-range": "^3.0.0",
|
|
35
35
|
"p-defer": "^4.0.0",
|
|
36
36
|
"random-int": "^3.0.0",
|
|
37
|
-
"time-span": "^5.
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"typescript": "^5.
|
|
41
|
-
"xo": "^0.
|
|
37
|
+
"time-span": "^5.1.0",
|
|
38
|
+
"tsd": "^0.29.0",
|
|
39
|
+
"tsx": "^4.6.2",
|
|
40
|
+
"typescript": "^5.3.3",
|
|
41
|
+
"xo": "^0.56.0"
|
|
42
42
|
},
|
|
43
43
|
"ava": {
|
|
44
|
+
"workerThreads": false,
|
|
44
45
|
"files": [
|
|
45
46
|
"test/**"
|
|
46
47
|
],
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"ts": "module"
|
|
49
50
|
},
|
|
50
51
|
"nodeArguments": [
|
|
51
|
-
"--
|
|
52
|
+
"--import=tsx/esm"
|
|
52
53
|
]
|
|
53
54
|
},
|
|
54
55
|
"xo": {
|