multi

Asynchronous execution library

Multi

Run asynchronous methods sequentially or in parallel.

Multi provides a mechanism to run callbacks asynchronously in sequence, or in parallel.

Execution can be interrupted if there is an error. After all callbacks have finished executing, the library will provide [err, results], containing the errors (null if none) and the respective results of the callbacks.

To install multi:

npm install multi

To install multi's dependencies:

npm install

You can also install the dependencies with make deps.

To run the test suites:

make test

Multi works with objects that have asynchronous methods. It creates a wrapper with the same methods as the original, which can be run either in sequence or in parallel.

The following example wraps the fs module in a Multi object, and performs some operations:

var fs = require('fs'),
    Multi = require('multi');
  
var mfs = new Multi(fs);
 
mfs.readFile('./assets/hello.html', 'utf-8');
mfs.readdir('./assets/');
mfs.readFile('./assets/style.css', 'utf-8');
mfs.lstat('./assets/text.txt');
 
mfs.exec(function(errresults) {
  console.log([err, results]);
});

There are several examples provided on the various uses of Multi, available in the examples/ directory.

The following options are accepted in the Multi configuration object (second parameter of constructor):

parallel: Determines if the methods will run in parallel. Defaults to false

interrupt: Interrupts execution if an error is encountered. Defaults to false

Copyright © 2012, Ernesto Méndez. (MIT License)

See LICENSE for more info.