gpt4 book ai didi

javascript - 使用 NodeJS 和 Sequelize 进行控制流

转载 作者:行者123 更新时间:2023-12-03 22:42:49 27 4
gpt4 key购买 nike

我有以下功能:

 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com