我有以下功能:
function retrieveNotifications(promotions) {
promotions.forEach( function(promotion) {
//find all notification groups that have to be notified
db
.Notification
.findAll()
.then(function (notifications) {
//some code that adds notifications to an object
});
});
};
我如何重组它以等到所有通知都添加到对象中。我不能使用
.then
因为它会因为 forEach
被多次调用
最佳答案
我建议使用异步库:https://github.com/caolan/async
基本上它会是这样的:
async.parallel([
// tasks..
],
function () {
// this is the final callback
})
关于javascript - 使用 NodeJS 和 Sequelize 进行控制流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28770141/