I'd like to make an addition using Async() in NodeJS but it doesn't work...
My code :
var id = request.params.id;
var self = this;
var total;
var asyncTasks = [];
asyncTasks.push(function(callback){
self.orderDao.getAllOfUser(id).success(function (orders) {
orders.forEach( function(order){
total = total + order.price; // here I'd like to make the addition
console.log(total);
});
});
callback();
});
async.parallel(asyncTasks, function(){
self.orderDao.getAllOfUser(id).success(function (orders) {
response.render('order/index', {orders: orders, total: total});
});
});
Result of total : NaN
callback();be moved up one block? Then it'll be called when your query & the loop are done. Right nowasync.parallel's callback might be executed before your queries have time to finish.