1.0.3 • Published 9 years ago
async-straight v1.0.3
async-straight
A light weight module to run asynchronous tasks in series, inspired from async.series
Installation
npm install async-straightAPI
var straight = require('async-straight')straight(tasks, callback)
It executes each function in tasks in series and after their execution calls the optional callback(if supplied).
Arguments
tasks- An array or object containing functions to run, each function is passed acb(err, result)it must call on completion with an errorerr(which can benull) and an optionalresultvalue.callback(err, results)- An optional callback to run once all the functions have completed. This function gets a results array (or object) containing all the result arguments passed to thetaskcallbacks.
Example
straight([
function(cb) {
setTimeout(function() {
cb(null, "hello");
}, 1000);
},
function(cb) {
setTimeout(function() {
cb(null, "world");
}, 2000);
}
], function(err, result) {
// result is equal to ["hello","world"]
});
// an example using an object instead of an array
straight({
one: function(cb){
setTimeout(function(){
cb(null, "ping");
}, 200);
},
two: function(callback){
setTimeout(function(){
cb(null, "pong");
}, 100);
}
},
function(err, results) {
// results is now equal to: {one: "ping", two: "pong"}
});Tests
npm run testAuthor
Tabish Rizvi (sayyidtabish@gmail.com)
License
MIT
