queue-up
Simple promise-based function queue
Cool way to enqueue rate-limited operations. Even cooler when used with Promise-returning functions.
Install
$ npm install --save queue-up
Usage
const ghGot = require('gh-got');
const Queue = require('queue-up');
const queue = new Queue(60 * 60 * 1000 / 5000);
const users = [
'dsblv',
'strikeentco',
'sindresorhus',
'octocat'
];
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);
});
}
API
new Queue([interval], [promiseModule])
Creates new instance of Queue.
interval
Type: number
Default: 1000
promiseModule
Type: function
Pass custom Promise module to use instead of the native one.
queue.up([value]) → promise
Alias: queue.enqueue()
Returns a Promise
which is resolved in specified time after previous one.
value
Value to be passed to resolve
handler function:
queue.up('hello').then(console.log);
License
MIT © Dimzel Sobolev