-
-
Save Jxck/802642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* @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