【发布时间】:2018-09-29 15:24:11
【问题描述】:
如何打破续集承诺 .then({})。我想打破 then 承诺的出口并打破循环。如果条件触发。代码与以下相同。不是我的确切代码。
int i = 0;
while(i<result.length){
db.Model.findAll({
where:{
x : X,
w : W,
z : z
}).then(result => {
if(result[i].x == null || result[i].x == undefined){
// update and break here!
update(): // something like that
// how i break the outer loop.
}
if(result[i].w > 0){
// how i break the outer loop.
}
if(result[i].z < 100){
// how i break the outer loop.
}
})
i++;
}
【问题讨论】:
-
嗯,我不完全理解这里发生了什么,但是为什么一个简单的
break表达式不起作用?也许像result.some()这样的东西,然后在你想休息时返回 true 可能会更好。 -
寻找取消令牌或者你可以使用bluebird
-
我很抱歉,我有一个错误的示例代码给你。 e 更新了示例,希望您现在可以得到它。谢谢。
-
我不明白您的编辑。
result未定义。 -
2 个问题.. 1) 一遍又一遍地执行相同的数据库查询有什么意义..? 2) 你必须将你的
while循环移动到then阶段,并为下一个then阶段返回一些有意义的东西。
标签: javascript node.js promise sequelize.js