似乎在将 async/await 与 .reduce() 合并时遇到了一些问题,如下所示:
const data = await bodies.reduce(async(accum, current, index) => {
const methodName = methods[index]
const method = this[methodName]
if (methodName == 'foo') {
current.cover = await this.store(current.cover, id)
console.log(current)
return {
...accum,
...current
}
}
return {
...accum,
...method(current.data)
}
}, {})
console.log(data)
该data
对象被记录之前的this.store
完成...
我知道您可以使用Promise.all
异步循环,但这适用于.reduce()
?