Sequelize JS / Bluebird:从asynchronous并行数据库调用开始

我有个问题。

我想开始2分贝的电话,然后继续承诺链。

我做的一个相当怪异的做法是像这样开始承诺:

db.Model.find().then(function() { return [ firstcall, secondcall ] }).spread(function(resultFromFirstCall, resultFromSecondCall) { //do something once both calls completed }); 

用空数据库调用启动promise链可以吗? 或者,还有更好的方法。

我知道我可以引入asynchronous库,但是我认为这是一个更清洁的方法,如果没有性能影响,使空的db.Model.find()调用。

我不知道什么是空的find电话会在这里做,因为我从来没有使用SequelizeJS,但是我很确定你要找的可能是Promise.join

 Promise.join( firstCall, secondCall, function( firstResult, secondResult ) { // Whatever }); 

过了一段时间,我发现了一个更好的方法来做到这一点。

 Promise.resolve().then(function() { return [ firstCall(), secondCall() ]; }).spread(function(resultFromFirst, resultFromSecond) { //do something with resultFromFirst and resultFromSecond });