I'm wondering what the best way to handle multiple concurrent operation in node.js. For example, let's say a given HTTP request needs to make 3 database queries before it can render the response, but each of the requests are independent. My current naive implementation works like this (in pseudo code)
doRequest1(query, function (response1) {
doRequest2(someQuery, function (response2) {
doRequest3(someQuery, function (response3) {
renderHTML(response1,response2,response3);
});
});
});
Is there a better way to do this? It seems wasteful to wait for the response to each of the queries to start the next one.