Comparing version 1.1.1 to 1.2.0
10
index.js
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
var Queue = module.exports = function (interval, P) { | ||
@@ -7,3 +9,3 @@ this.interval = (interval > 0) ? interval : 1000; | ||
Queue.prototype.up = Queue.prototype.enqueue = function () { | ||
Queue.prototype.up = Queue.prototype.enqueue = function (value) { | ||
var now = Date.now(); | ||
@@ -20,4 +22,8 @@ | ||
return new this.Promise(function (resolve) { | ||
setTimeout(resolve, remains); | ||
var asyncSetTimer = remains || typeof setImmediate === 'undefined' ? setTimeout : setImmediate; | ||
asyncSetTimer(function () { | ||
resolve(value); | ||
}, remains); | ||
}); | ||
}; |
{ | ||
"name": "queue-up", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Simple promise-based function queue", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -25,3 +25,3 @@ # queue-up [![Build Status](https://travis-ci.org/dsblv/queue-up.svg?branch=master)](https://travis-ci.org/dsblv/queue-up) | ||
[ | ||
const users = [ | ||
'dsblv', | ||
@@ -31,9 +31,13 @@ 'strikeentco', | ||
'octocat' | ||
].forEach(user => { | ||
queue.up() | ||
.then(ghGot('users/' + user, {token: 'koten'})) | ||
]; | ||
for (var i in users) { | ||
queue.up(users[i]) | ||
.then(user => { | ||
return ghGot('users/' + user, {token: 'koten'}); | ||
}) | ||
.then(data => { | ||
console.log(data.body.name + ' is in ' + data.body.location); | ||
}); | ||
}); | ||
} | ||
@@ -45,5 +49,5 @@ ``` | ||
### `queue = new Queue([interval], [promiseModule])` | ||
### new Queue([interval], [promiseModule]) | ||
Create new instance of Queue. Or several instances if you need different queues. | ||
Creates new instance of Queue. | ||
@@ -62,3 +66,3 @@ #### interval | ||
### `queue.up()` → `promise` | ||
### queue.up([value]) → `promise` | ||
@@ -69,5 +73,13 @@ Alias: `queue.enqueue()` | ||
#### value | ||
Value to be passed to `resolve` handler function: | ||
```js | ||
queue.up('hello').then(console.log); | ||
//=> hello | ||
``` | ||
## License | ||
MIT © [Dimzel Sobolev](http://vk.com/sobo13v) |
3715
20
81