1.0.2 • Published 7 years ago

promise-rockfall v1.0.2

Weekly downloads
8
License
LGPL-3.0
Repository
github
Last release
7 years ago

promise-rockfall

master branch build status dependencies version status

NPM

desscription

Runs an array of promises in chunked series one after another.

installation

npm i -S promise-rockfall

usage

const rockfall = require('promise-rockfall');
// Array of promises
const promises = Array(100).fill(null).map(() => (Promise.resolve(Math.random())));
// Process promises in several batches of 10 promises at max.
rockfall(promises, 10);
// It is possible do something when each batch is resolved
rockfall(promises, 10, (rs) => {console.log(rs);});
// It is possible to do something when everything is resovled
rockfall(promises, 10)
  .then(() => {console.log('all done');})
  .catch((err) => {console.error(err);});

API

rockfall(functions, size, batchThen) -> promise

Runs an array of promises in chunked series one after another.

functions

Required Type: array[function]

size

Optional Type: integer

batches' size

batchThen

Optional Type: function

function that takes the resolution of one batch of promises in input