• Stars
    star
    318
  • Rank 127,003 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple async batch with concurrency control and progress reporting

batch

NPM Version NPM Downloads Build Status Test Coverage

Simple async batch with concurrency control and progress reporting.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install batch

Usage

var Batch = require('batch')

new Batch([options], [...fns])

Create a new Batch, optionally passing an options object and/or a list of functions (fns) to queue.

The options object may contain the following keys:

  • concurrency: set the default concurrency for the Batch, which can be changed using batch.concurrency(n).
  • throws: set the default throws for the Batch, which can be changed using batch.throws(throws).

batch.concurrency(n)

Set concurrency to n.

batch.end([cb])

Execute all queued functions in parallel, executing cb(err, results).

batch.push(fn)

Queue a function.

batch.throws(throws)

Set whether Batch will or will not throw up.

progress event

Contains the "job" index, response value, duration information, and completion data.

{ index: 1,
  value: 'bar',
  pending: 2,
  total: 3,
  complete: 2,
  percent: 66,
  start: Thu Oct 04 2012 12:25:53 GMT-0700 (PDT),
  end: Thu Oct 04 2012 12:25:53 GMT-0700 (PDT),
  duration: 0 }

Example

var Batch = require('batch')
  , batch = new Batch;

batch.concurrency(4);

ids.forEach(function(id){
  batch.push(function(done){
    User.get(id, done);
  });
});

batch.on('progress', function(e){

});

batch.end(function(err, users){

});

License

MIT

More Repositories

1

page.js

Micro client-side router inspired by the Express router
JavaScript
7,621
star
2

move.js

CSS3 backed JavaScript animation framework
JavaScript
4,712
star
3

node-progress

Flexible ascii progress bar for nodejs
JavaScript
2,913
star
4

masteringnode

Open source eBook for nodejs - written w/ markdown, outputs to various formats (pdf, mobi, epub, html, etc)
JavaScript
1,834
star
5

express-resource

Resourceful routing for Express
JavaScript
1,414
star
6

uikit

UIKit - modern ui components for the modern web
JavaScript
1,320
star
7

deploy

Minimalistic deployment shell script
Shell
1,148
star
8

screenshot-app

website screenshot service & app - powered by node.js, express, redis, node-canvas, phantomjs and more
JavaScript
850
star
9

expresso

use mocha
JavaScript
760
star
10

bytes.js

node byte string parser
JavaScript
440
star
11

node-jscoverage

jscoverage modified to support SSJS
C++
400
star
12

stack

Minimalist provisioning tool written in Go.
Go
310
star
13

express-messages

Express flash notification message rendering
JavaScript
261
star
14

google-search

Ruby - Google Search API
Ruby
258
star
15

express-params

Express param pre-condition functions
JavaScript
146
star
16

stats

JavaScript source statistics with simple API & CLI written with node.js
JavaScript
78
star
17

histogram

JavaScript canvas histogram component
JavaScript
68
star
18

go-debug

Old anti-pattern go-debug thing
Go
56
star
19

minstache

Mini mustache compiling to stand-alone functions
JavaScript
53
star
20

go-hpc

HTTP RPC codec for Gorilla RPC v2.
Go
29
star
21

connect-render

Template Render helper for connect: res.render(view, options).
JavaScript
17
star
22

readme

repos are now at /tj/*
1
star