Using node.js/express.js, here is an example of a typical problem that I face with asynchronous code (function rendering a page on a request with 2 db call):
exports.index = function(req, res){
res.render('index', {
data1: getData1(),
data2: getData2()
});
};
Here is what one function could look like:
function getData1() {
var assets = db.get("assets");
assets.find().on('success', function (docs) {
// What to do ?
});
}
I tried using async.js which is a very helpful module, but I'm still missing knowledge on how to do with a case like this.
And can someone suggest good resources for best practice regarding asynchronous javascript coding ?