Nodejs: Passing function specific variables to Async.parallel()
asynchronous, javascript, node.js
Solution
You should respect the callback as last argument nodejs convention when you write functions. That way you could have use Function.bind to call your functions instead.
var queryx = function(A,B,C,callback){ .... ; callback(err,result) };
async.parallel([queryx.bind(null,A1,B2,A3),...,],callback);
bind returns a partial application :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
Problem
I am have a bunch of long running database queries I need to get done before I render a page in node. Each of these queries require a few of their own variables. Is there an easy way to pass variables to the async.parallel() utility in nodejs? ``` async.parallel([ queryX(callback, A1, A2, A3), queryX(callback, B1, B2, B3), queryY(callback, C1, C2, C3), queryY(callback, D1, D2, D3), queryZ(callback, E1, E2, E3), queryZ(callback, F1, F2, F3), ], function(err, results) { /*Do Render Stuff with Results*/} ); ```