db.Question.findAll({
where: {
PassageId: dbPassage.id,
active: true,
level: {
$lte: startLevel,
$gte: endLevel
}
},
order: [db.Sequelize.fn('RANDOM')]
}).each(function(dbQuestion) {
// End early if some condition
});
我正在使用bluebird
,我想知道是否有可能提前退出.each
?
答案 0 :(得分:1)
我会做那样的事情。 (未经测试)
var searchPromise = Promise.resolve();
searchPromise = db.Question.findAll({
where: {
PassageId: dbPassage.id,
active: true,
level: {
$lte: startLevel,
$gte: endLevel
}
},
order: [db.Sequelize.fn('RANDOM')]
}).each(function(dbQuestion) {
if (condition === true) {
searchPromise.cancel();
}
}).cancellable();