Q.然后不等待承诺

时间:2016-02-17 19:08:50

标签: javascript node.js mongodb q

更新 - 解决方案: 我是为了循环而应该使用MongoDB $in功能 - details here

我有以下Q.all块:

Q.all([
   getFirstBlock(),
   getSecondBlock(),
])
.then(function(){
   getSecondBlockProcessed();
})
.then(function(){
   res.json(completeArray);
});

我遇到的问题是当我进入最后then块时,我注意到函数getSecondBlockProcessed尚未完成。 第一个Q.all中的所有内容都已完成。 为什么这个承诺没有得到解决?

问题的方法如下:

var getSecondBlockProcessed = function() {
    return Q.promise(function(resolve, reject) {
      for (var i=0; i<mostInRegion.length; i++){
        Person.find(
          {_id: mostInRegion[i]['_id']},
          {question:1, country: 1},
          function(err, found) {
            mostInRegion2.push(found);
          })
      }
      resolve();
      });
}

任何帮助都会受到赞赏/我忽略了什么?

由于

0 个答案:

没有答案
相关问题