qbatcher
v1.0.2
Published
A module that allows batching of async operations with optional time limits (e.g. 50 API requests at a time or 50 API requests / 10 seconds)
Downloads
15
Maintainers
Readme
QBatcher
Batch promises and/or limit them by time intervals.
Suited for issueing request to rate limited APIS (e.g 50 requests/ 10 secconds)
Installation
npm install qbatcher
Api
QBatcher.run(array: Collection, i => promise: Iteratee, int: batchSize, int: intervalLimit (milliseconds) )
Keep in mind that the interval limit should be milliseconds
The Promise: Iteratee
will be called for each element in the Collection.
Use:
var QBatcher = require('qbatcher');
QBatcher.run([ 1, 2, 3, 4, 5], function (payload) {
return new Promise(function(resolve) {
setTimeout(function() { resolve(payload * 100) }, 100);
});
}, 2, 5000)
.then(function (results) {
console.log(results);
});