I am having an express app. I want to have parallel flow for an array of functions that I want to run. I am thinking of using async module for doing so.
I want to know if there is any other module which will be more better than this?
Secondly I want to know is it necessary that these functions be Asynchronous? Lets say I have code like this
var sum = function(x, y){
return (x + y)
}
async.parallel([
function(callback){
setTimeout(function(){
result = sum (x, y); //just an example for a synchronous function
callback(null, result);
}, 100);
},
function(callback){
result = sum (x, y); //just an example for a synchronous function
callback(null, result);
}
],
// optional callback
function(err, results){
console.log(result);
// the results array will equal ['one','two'] even though
// the second function had a shorter timeout.
});
SO as you can inside this there are functions which are synchronous. So will still this two run in parallel?
I have also heard that in node.js only I/O tasks can run in parallel as node.js is single threaded. Is it true? And so if I don't have I/O tasks that in async module also they won't run in parallel rather just appear to?
Please help.