【发布时间】:2018-10-03 02:28:15
【问题描述】:
我正在执行以下代码:
let promises = []
querySnapshot.forEach(function (doc) {
promises.push(
promiseFunction()
.then((postCounters) => {
promiseFunction2()
.then((myRate) => {
console.log('save array with postCounters AND myRate data')
})
})
)
})
Promise.all(promises).then(() => {
console.log('the array with postCounters AND myRate data')
})
事情越来越不对劲了。返回的 Promise.all 不会等到 promiseFunction2 运行,所以第二个函数不起作用,我没有在我的数组中获取 promiseFunction2 数据,只是第一个。
我认为正在发生的事情是:Promise.all 在所有 promiseFunction 运行后得到,但它不会等到第二个函数,我想在得到所有承诺之前等待两者都完成,我应该使用两个 Promise 。全部???
我对 Promise.all 的语法不是很熟悉,我只是使用 promiseFunction().then() 方法
(使我的代码保持一致以良好扩展的事件)
【问题讨论】:
标签: javascript arrays promise