promise-queue
Advanced tools
Comparing version 2.0.1 to 2.1.1
@@ -113,2 +113,20 @@ /* global define, Promise */ | ||
/** | ||
* Number of simultaneously running promises (which are resolving) | ||
* | ||
* @return {number} | ||
*/ | ||
Queue.prototype.getPendingLength = function () { | ||
return this.pendingPromises; | ||
}; | ||
/** | ||
* Number of queued promises (which are waiting) | ||
* | ||
* @return {number} | ||
*/ | ||
Queue.prototype.getQueueLength = function () { | ||
return this.queue.length; | ||
}; | ||
/** | ||
* @returns {boolean} true if first item removed from queue | ||
@@ -115,0 +133,0 @@ * @private |
@@ -5,3 +5,3 @@ { | ||
"name" : "promise-queue", | ||
"version" : "2.0.1", | ||
"version" : "2.1.1", | ||
"contributors" : [ | ||
@@ -8,0 +8,0 @@ { |
@@ -13,2 +13,9 @@ # promise-queue [![NPM Version](https://badge.fury.io/js/promise-queue.png)](https://npmjs.org/package/promise-queue) [![Build Status](https://travis-ci.org/azproduction/promise-queue.png?branch=master)](https://travis-ci.org/azproduction/promise-queue) [![Coverage Status](https://coveralls.io/repos/azproduction/promise-queue/badge.png?branch=master)](https://coveralls.io/r/azproduction/promise-queue) [![Dependency Status](https://gemnasium.com/azproduction/promise-queue.png)](https://gemnasium.com/azproduction/promise-queue) | ||
## Interface | ||
- `new Queue(Number maxConcurrent, Number maxQueued): Queue` | ||
- `Queue#add(Function generator): Promise` - adds function argument that generates a promise to the queue | ||
- `Queue#getQueueLength(): Number` - returns current length of buffer(added but not started promise generators) `it <= maxQueued` | ||
- `Queue#getPendingLength(): Number` - returns number of pending(concurrently running) promises `it <= maxConcurrent` | ||
## Example | ||
@@ -59,2 +66,25 @@ | ||
### Getting number of pending promises and queue(buffered promises) length | ||
```js | ||
var maxConcurrent = 1; | ||
var maxQueue = 1; | ||
var queue = new Queue(maxConcurrent, maxQueue); | ||
queue.add(function () { | ||
queue.getQueueLength() === 0; | ||
queue.getPendingLength() === 1; | ||
return somePromise(); | ||
}); | ||
queue.add(function () { | ||
queue.getQueueLength() === 0; | ||
queue.getPendingLength() === 0; | ||
return somePromise(); | ||
}); | ||
queue.getQueueLength() === 1; | ||
queue.getPendingLength() === 1; | ||
``` | ||
[Live example](http://jsfiddle.net/RVuEU/1/) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
51552
505
89