我正在使用Sails,Waterline和Async库
function Outerfunction(listOfProducts) {
var salesOrderId = 1; //some id
var prom = [];
for (var i = 0; i < listOfProducts.length; i++) {
var qty = listOfProducts[i].quantity;
var prod = listOfProducts[i].productName;
var update = function(qty, prod, SalesOrderId) {
CardImages.update({
where: {
productName: prod,
isSold: false,
readyToSell: true
}
}, {
order: SalesOrderId,
isSold: true
})
.exec(function(err, updatedRecords) {
if (err) return err;
return updatedRecords;
});
}
prom.push(update);
}
async.parallel(prom, function(err, result) {
//this callback never gets called
console.log("database calls done");
});
}
我正在尝试使用for循环更新数据库,此代码工作正常并更新数据库,但是当所有记录都更新时,我的async.parallel
回调不会被调用。