Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 67ad71b8a1
Fetching contributors…

Cannot retrieve contributors at this time

48 lines (34 sloc) 0.972 kB

Common patterns for asynchronous code, minimalistic version (async-mini)

If you only need async.series() and async.parallel() in the most simplest, stable and predictable form, then this module is for you.

Usage

npm install async-mini
var async = require('async-mini');

var funcs = [
    function(cb) {
        cb(null, 'done 1');
    },
    function(cb) {
        cb(null, 'done 2');
    }
];

var funcs2 = {
    one: function(cb) {
        cb(null, 'done 1');
    },
    two: function(cb) {
        cb(null, 'done 2');
    }
};

var cb = function(err, res) {
    console.log(arguments);
};

async.series(funcs, cb);

async.parallel(funcs, cb);

async.parallel(funcs2, cb);

The above code will print:

{ '0': null, '1': [ 'done 1', 'done 2' ] }
{ '0': null, '1': { '0': 'done 1', '1': 'done 2' } }
{ '0': null, '1': { one: 'done 1', two: 'done 2' } }

Of course, the above two .parallel() calls should themselves be inside a .series() call, but this is omitted for brevity of the exmaple.

Jump to Line
Something went wrong with that request. Please try again.