0.0.5 • Published 8 years ago

batch-manager v0.0.5

Weekly downloads
3
License
ISC
Repository
github
Last release
8 years ago

batch-manager NPM version Build Status Dependency Status Coverage percentage

Easily batch the execution of functions as promises.

Installation

$ npm install --save batch-manager

Usage

var BatchManager = require('./BatchManager');
var Q = require('q');

var httpGet = function (uri, options) {
  return Q.denodeify(require('request').get)(uri, options)
    .spread(function (resp) {
      return resp;
    });
};

// Create a new `BatchManager` object, with a 5 task batch size.
var bm = new BatchManager(5);

for (var i = 0; i < 20; i++) {
  // Add functions to the `BatchManager`'s internal queue.
  bm.add(httpGet, ['http://api.randomuser.me/', { qs: { gender: 'female' } }]);
}

// Launch the `BatchManager` into action - the queued set of functions are invoked in batches.
bm.run()
  .then(function (responses) {
    responses.map(function (resp, index) {
      console.log('Request No. ' + index + '. \tResponse Status: ' + resp.statusCode);
    });
  });

License

ISC © Rajiv Bose

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago