Skip to content

Instantly share code, notes, and snippets.

@Jxck
Forked from yssk22/paralell.js
Created January 30, 2011 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jxck/802642 to your computer and use it in GitHub Desktop.
Save Jxck/802642 to your computer and use it in GitHub Desktop.
/***
* @function make the parallel request filters and finish with the last filter.
*
* @example
*
* misc.parallel(
* func1, func2, func3, func4
* );
*
* func1 ---+
* |
* func2 ---+---> func4
* |
* func3 ---+
*
* all the filter functions takes 3 arguments (request, response, next)
* as usual as Express way.
*/
exports.parallel = function(){
var list = arguments;
return function(req, res, next){
var current = 0;
var len = list.length;
var last = list[len-1];
function pass(i){
return function(){
current += 1;
if( current == len - 1 ){
last(req, res, next);
}
};
}
for(var i=0; i<len-1;i++){
var fun = list[i];
fun(req, res, pass(i));
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment