Skip to content

Instantly share code, notes, and snippets.

@79yuuki
Created August 7, 2013 11:05
Show Gist options
  • Save 79yuuki/6173124 to your computer and use it in GitHub Desktop.
Save 79yuuki/6173124 to your computer and use it in GitHub Desktop.
npm batch demo
var Batch = require('batch')
, batch = new Batch;
var self = this;
batch.concurrency(4);
var ids = [0,1,2,3];
var fleetName = ['加賀', '赤城', '島風', '出雲'];
function organizeFleet(id, done) {
var fleet = fleetName[id];
console.log('organized', fleet);
done(null, fleet);
}
ids.forEach(function(id) {
batch.push(function(done) {
organizeFleet(id, done);
});
});
batch.on('progress', function(e) {
console.log('progress', e.complete / e.total * 100, '%');
});
batch.end(function(err, fleets) {
console.log('results', fleets);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment