Comparing version 6.5.0 to 6.6.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' | 'idle'> { | ||
export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsType> = PriorityQueue, EnqueueOptionsType extends QueueAddOptions = DefaultAddOptions> extends EventEmitter<'active' | 'idle' | 'add' | 'next'> { | ||
private readonly _carryoverConcurrencyCount; | ||
@@ -12,0 +12,0 @@ private readonly _isIntervalIgnored; |
@@ -49,2 +49,3 @@ "use strict"; | ||
this._tryToStartAnother(); | ||
this.emit('next'); | ||
} | ||
@@ -168,2 +169,3 @@ _resolvePromises() { | ||
this._tryToStartAnother(); | ||
this.emit('add'); | ||
}); | ||
@@ -170,0 +172,0 @@ } |
{ | ||
"name": "p-queue", | ||
"version": "6.5.0", | ||
"version": "6.6.0", | ||
"description": "Promise queue with concurrency control", | ||
@@ -51,8 +51,8 @@ "license": "MIT", | ||
"@types/benchmark": "^1.0.31", | ||
"@types/node": "^14.0.14", | ||
"@types/node": "^14.0.23", | ||
"ava": "^2.0.0", | ||
"benchmark": "^2.1.4", | ||
"codecov": "^3.3.0", | ||
"codecov": "^3.7.1", | ||
"del-cli": "^3.0.0", | ||
"delay": "^4.2.0", | ||
"delay": "^4.4.0", | ||
"in-range": "^2.0.0", | ||
@@ -63,4 +63,4 @@ "nyc": "^15.0.0", | ||
"ts-node": "^8.3.0", | ||
"typescript": "^3.9.5", | ||
"xo": "^0.32.0" | ||
"typescript": "^3.9.7", | ||
"xo": "^0.32.1" | ||
}, | ||
@@ -83,3 +83,2 @@ "ava": { | ||
"@typescript-eslint/member-ordering": "off", | ||
"@typescript-eslint/prefer-readonly-parameter-types": "off", | ||
"node/no-unsupported-features/es-syntax": "off", | ||
@@ -86,0 +85,0 @@ "@typescript-eslint/no-floating-promises": "off", |
@@ -1,2 +0,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) | ||
# p-queue [![Build Status](https://travis-ci.com/sindresorhus/p-queue.svg?branch=master)](https://travis-ci.com/github/sindresorhus/p-queue) [![codecov](https://codecov.io/gh/sindresorhus/p-queue/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/p-queue) | ||
@@ -105,3 +105,3 @@ > Promise queue with concurrency control | ||
Whether the task must finish in the given interval or will be carried over into the next interval count. | ||
If `true`, specifies that any [pending](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) Promises, should be carried over into the next interval and counted against the `intervalCap`. If `false`, any of those pending Promises will not count towards the next `intervalCap`. | ||
@@ -249,2 +249,36 @@ ### queue | ||
#### add | ||
Emitted every time the add method is called and the number of pending or queued tasks is increased. | ||
#### next | ||
Emitted every time a task is completed and the number of pending or queued tasks is decreased. | ||
```js | ||
const delay = require('delay'); | ||
const {default: PQueue} = require('p-queue'); | ||
const queue = new PQueue(); | ||
queue.on('add', () => { | ||
console.log(`Task is added. Size: ${queue.size} Pending: ${queue.pending}`); | ||
}); | ||
queue.on('next', () => { | ||
console.log(`Task is completed. Size: ${queue.size} Pending: ${queue.pending}`); | ||
}); | ||
const job1 = queue.add(() => delay(2000)); | ||
const job2 = queue.add(() => delay(500)); | ||
await job1; | ||
await job2; | ||
//=> 'Task is added. Size: 0 Pending: 1' | ||
//=> 'Task is added. Size: 0 Pending: 2' | ||
await queue.add(() => delay(600)); | ||
//=> 'Task is completed. Size: 0 Pending: 1' | ||
//=> 'Task is completed. Size: 0 Pending: 0' | ||
``` | ||
## Advanced example | ||
@@ -251,0 +285,0 @@ |
Sorry, the diff of this file is not supported yet
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
30783
499
401