Multi
Asynchronous execution library.
Features
- Run callbacks asynchronously in sequence or in parallel
- Wraps around an object with asynchronous methods
- Stops execution if error encountered
- Reusable call stack if needed
Installation
To install multi:
npm install multi
Install from git repository:
git clone https://github.com/derdesign/multi.git
Running tests:
make test
Usage
Multi creates a wrapper object containing the same methods as the original object. The wrapped methods can then be run either
in sequence or in parallel, by providing the proper options to the Multi::exec
method.
The following example wraps the fs
module in a Multi object, to perform async file operations:
var fs = ;var Multi = ; var mfs = fs; mfs;mfs;mfs;mfs; mfs;
API
Multi(options)
Multi constructor. Receives an options object. Available options are:
-
parallel: Determines if the methods will run in parallel. Defaults to
false
-
interrupt: Interrupts execution if an error is encountered. Defaults to
false
-
flush: Clears the call stack after running
exec
. Defaults totrue
multi.exec(callback)
Runs the wrapper methods asynchronously using the configuration passed to the multi constructor. The callback has a
signature of (err, results)
. If an error occurs, err
will be an array with the errors from the execution stack.
The results
object is an array containing the arguments provided to callbacks in the execution stack.
Events
pre_exec: Emitted before running the call stack
post_exec: Emitted upon completion, before calling the exec
callback
License
multi
is MIT Licensed