【发布时间】:2015-04-30 11:08:47
【问题描述】:
我有以下功能:
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会被多次调用
【问题讨论】:
-
你应该使用
Promise.map而不是forEach,这样你就可以为你的结果返回一个promise
标签: javascript node.js promise sequelize.js bluebird