Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-queue

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-queue - npm Package Compare versions

Comparing version 2.0.1 to 2.1.1

18

lib/index.js

@@ -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

2

package.json

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc