Simple helper to run asynchronous functions and wait for them to finish before calling a callback function.
Callback use the node.js format:
cb = function(err, result...){...}
Example with dummy asynchronous functions:
waitgroup([function(cb){
setTimeout(function(){
cb(null,2);
}, 2);
}, function(cb){
setTimeout(function(){
cb(null,1);
}, 1);
}], function(err, results){
console.log("Done",results);
});
void = waitgroup( array funcs, function done )
Wait for all functions sent in the funcs array to complete a call the done function.
-
array funcs:
An array of asynchronous function. See below.
-
function done:
Will be called when all funcs functions are done. Or when a funcs function produce an error.
function(func done)
The callback passed as argument to every funcs function when they are call by workgroup().
-
func done:
The callback to indiquate when a funcs function is finished, or produce an error.
function(? err, ? result)
TODO: finish it