Comparing version 2.0.0 to 2.1.0
'use strict'; | ||
var delay = require('delay'); | ||
var Queue = module.exports = function (interval) { | ||
var Queue = module.exports = function (interval, initialValue) { | ||
this.interval = interval || 1000; | ||
this.remaining = Promise.resolve(); | ||
this.remaining = Promise.resolve(initialValue); | ||
}; | ||
@@ -8,0 +8,0 @@ |
{ | ||
"name": "queue-up", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Simple promise-based function queue", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -32,3 +32,3 @@ # queue-up [![Build Status](https://travis-ci.org/dsblv/queue-up.svg?branch=master)](https://travis-ci.org/dsblv/queue-up) | ||
opts = { | ||
const opts = { | ||
token: 'the-private-token' | ||
@@ -47,3 +47,3 @@ }; | ||
### new Queue([interval]) | ||
### new Queue([interval, initialValue]) | ||
@@ -57,3 +57,26 @@ Creates new instance of Queue. | ||
Time in `ms` from when previous function resolves to when next is invoked. | ||
#### initialValue | ||
Type: `any` | ||
Default: `undefined` | ||
Every function in a queue gets result of the previous one as an argument. If you specify `initialValue`, it will be fed to the first function: | ||
```js | ||
function double(value) { | ||
return value * 2; | ||
} | ||
const queue = new Queue(100, 1337); | ||
queue.up(double).then(console.log); | ||
//=> 2674 | ||
queue.up(double).then(console.log); | ||
//=> 5348 (after 100ms) | ||
``` | ||
### queue.up(fn) | ||
@@ -75,3 +98,3 @@ | ||
Like [`Promise.all()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all), but with interval between invocations. | ||
Enqueues several function and returns a `promise` that resolves to an `array` of all results. | ||
@@ -85,5 +108,15 @@ #### fns | ||
```js | ||
function double(value) { | ||
return value * 2; | ||
} | ||
const queue = new Queue(100, 1337); | ||
queue.all([double, double]).then(console.log); | ||
//=> [2674, 5348] (after 100ms) | ||
``` | ||
## License | ||
MIT © [Dmitriy Sobolev](https://github.com/dsblv) |
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
4383
118