-
-
Save Jxck/802642 to your computer and use it in GitHub Desktop.
Revisions
-
yssk22 created this gist
Dec 14, 2010 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ /*** * @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)); } }; }