Comparing version 6.3.0 to 6.4.0
@@ -9,3 +9,3 @@ import EventEmitter = require('eventemitter3'); | ||
*/ | ||
export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsType> = PriorityQueue, EnqueueOptionsType extends QueueAddOptions = DefaultAddOptions> extends EventEmitter<'active'> { | ||
export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsType> = PriorityQueue, EnqueueOptionsType extends QueueAddOptions = DefaultAddOptions> extends EventEmitter<'active' | 'idle'> { | ||
private readonly _carryoverConcurrencyCount; | ||
@@ -87,3 +87,3 @@ private readonly _isIntervalIgnored; | ||
*/ | ||
sizeBy(options: Partial<EnqueueOptionsType>): number; | ||
sizeBy(options: Readonly<Partial<EnqueueOptionsType>>): number; | ||
/** | ||
@@ -97,2 +97,3 @@ Number of pending promises. | ||
get isPaused(): boolean; | ||
get timeout(): number | undefined; | ||
/** | ||
@@ -102,4 +103,3 @@ Set the timeout for future operations. | ||
set timeout(milliseconds: number | undefined); | ||
get timeout(): number | undefined; | ||
} | ||
export { Queue, QueueAddOptions, DefaultAddOptions, Options }; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const priority_queue_1 = require("./priority-queue"); | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const empty = () => { }; | ||
@@ -14,2 +15,3 @@ const timeoutError = new p_timeout_1.TimeoutError(); | ||
constructor(options) { | ||
var _a, _b, _c, _d; | ||
super(); | ||
@@ -119,11 +121,9 @@ Object.defineProperty(this, "_carryoverConcurrencyCount", { | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion | ||
options = Object.assign({ carryoverConcurrencyCount: false, intervalCap: Infinity, interval: 0, concurrency: Infinity, autoStart: true, queueClass: priority_queue_1.default }, options | ||
// TODO: Remove this `as`. | ||
); | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
options = Object.assign({ carryoverConcurrencyCount: false, intervalCap: Infinity, interval: 0, concurrency: Infinity, autoStart: true, queueClass: priority_queue_1.default }, options); | ||
if (!(typeof options.intervalCap === 'number' && options.intervalCap >= 1)) { | ||
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${options.intervalCap}\` (${typeof options.intervalCap})`); | ||
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(_b = (_a = options.intervalCap) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''}\` (${typeof options.intervalCap})`); | ||
} | ||
if (options.interval === undefined || !(Number.isFinite(options.interval) && options.interval >= 0)) { | ||
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval}\` (${typeof options.interval})`); | ||
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(_d = (_c = options.interval) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : ''}\` (${typeof options.interval})`); | ||
} | ||
@@ -157,2 +157,3 @@ this._carryoverConcurrencyCount = options.carryoverConcurrencyCount; | ||
this._resolveIdle = empty; | ||
this.emit('idle'); | ||
} | ||
@@ -363,2 +364,5 @@ } | ||
} | ||
get timeout() { | ||
return this._timeout; | ||
} | ||
/** | ||
@@ -370,6 +374,3 @@ Set the timeout for future operations. | ||
} | ||
get timeout() { | ||
return this._timeout; | ||
} | ||
} | ||
exports.default = PQueue; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Port of lower_bound from http://en.cppreference.com/w/cpp/algorithm/lower_bound | ||
// Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound | ||
// Used to compute insertion index to keep queue sorted after insertion | ||
@@ -5,0 +5,0 @@ function lowerBound(array, value, comparator) { |
@@ -10,4 +10,4 @@ import { Queue, RunFunction } from './queue'; | ||
dequeue(): RunFunction | undefined; | ||
filter(options: Partial<PriorityQueueOptions>): RunFunction[]; | ||
filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[]; | ||
get size(): number; | ||
} |
@@ -28,6 +28,6 @@ "use strict"; | ||
const item = this._queue.shift(); | ||
return item && item.run; | ||
return item === null || item === void 0 ? void 0 : item.run; | ||
} | ||
filter(options) { | ||
return this._queue.filter(element => element.priority === options.priority).map(element => element.run); | ||
return this._queue.filter((element) => element.priority === options.priority).map((element) => element.run); | ||
} | ||
@@ -34,0 +34,0 @@ get size() { |
{ | ||
"name": "p-queue", | ||
"version": "6.3.0", | ||
"version": "6.4.0", | ||
"description": "Promise queue with concurrency control", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-queue", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"main": "dist/index.js", | ||
@@ -51,4 +52,2 @@ "engines": { | ||
"@types/node": "^12.12.7", | ||
"@typescript-eslint/eslint-plugin": "^1.11.0", | ||
"@typescript-eslint/parser": "^1.11.0", | ||
"ava": "^2.0.0", | ||
@@ -59,10 +58,9 @@ "benchmark": "^2.1.4", | ||
"delay": "^4.2.0", | ||
"eslint-config-xo-typescript": "^0.16.0", | ||
"in-range": "^2.0.0", | ||
"nyc": "^14.0.0", | ||
"nyc": "^15.0.0", | ||
"random-int": "^2.0.0", | ||
"time-span": "^3.1.0", | ||
"time-span": "^4.0.0", | ||
"ts-node": "^8.3.0", | ||
"typescript": "3.7.2", | ||
"xo": "^0.25.3" | ||
"typescript": "3.8.3", | ||
"xo": "^0.28.1" | ||
}, | ||
@@ -83,12 +81,6 @@ "ava": { | ||
"xo": { | ||
"extends": "xo-typescript", | ||
"extensions": [ | ||
"ts" | ||
], | ||
"rules": { | ||
"@typescript-eslint/member-ordering": "off", | ||
"@typescript-eslint/strict-boolean-expressions": "off", | ||
"@typescript-eslint/require-await": "off", | ||
"@typescript-eslint/no-misused-promises": "off", | ||
"require-atomic-updates": "off" | ||
"@typescript-eslint/prefer-readonly-parameter-types": "off", | ||
"node/no-unsupported-features/es-syntax": "off" | ||
} | ||
@@ -95,0 +87,0 @@ }, |
@@ -7,3 +7,2 @@ # p-queue [![Build Status](https://travis-ci.org/sindresorhus/p-queue.svg?branch=master)](https://travis-ci.org/sindresorhus/p-queue) [![codecov](https://codecov.io/gh/sindresorhus/p-queue/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/p-queue) | ||
## Install | ||
@@ -15,3 +14,2 @@ | ||
## Usage | ||
@@ -28,3 +26,3 @@ | ||
(async () => { | ||
await queue.add(() => got('sindresorhus.com')); | ||
await queue.add(() => got('https://sindresorhus.com')); | ||
console.log('Done: sindresorhus.com'); | ||
@@ -34,4 +32,4 @@ })(); | ||
(async () => { | ||
await queue.add(() => got('ava.li')); | ||
console.log('Done: ava.li'); | ||
await queue.add(() => got('https://avajs.dev')); | ||
console.log('Done: avajs.dev'); | ||
})(); | ||
@@ -46,3 +44,2 @@ | ||
## API | ||
@@ -174,3 +171,2 @@ | ||
#### .sizeBy(options) | ||
@@ -208,3 +204,2 @@ | ||
## Events | ||
@@ -233,4 +228,29 @@ | ||
``` | ||
#### idle | ||
Emitted every time the queue becomes empty and all promises have completed; `queue.size === 0 && queue.pending === 0`. | ||
```js | ||
const delay = require('delay'); | ||
const {default: PQueue} = require('p-queue'); | ||
const queue = new PQueue(); | ||
queue.on('idle', () => { | ||
console.log(`Queue is idle. Size: ${queue.size} Pending: ${queue.pending}`); | ||
}); | ||
const job1 = queue.add(() => delay(2000)); | ||
const job2 = queue.add(() => delay(500)); | ||
await job1; | ||
await job2; | ||
// => 'Queue is idle. Size: 0 Pending: 0' | ||
await queue.add(() => delay(600)); | ||
// => 'Queue is idle. Size: 0 Pending: 0' | ||
``` | ||
The `idle` event is emitted every time the queue reaches an idle state. On the other hand, the promise the `onIdle()` function returns resolves once the queue becomes idle instead of every time the queue is idle. | ||
## Advanced example | ||
@@ -306,3 +326,2 @@ | ||
## Custom QueueClass | ||
@@ -338,3 +357,2 @@ | ||
## Related | ||
@@ -348,3 +366,2 @@ | ||
--- | ||
@@ -351,0 +368,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32592
15
599
367