似乎在将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)
在 this.store
完成之前,data
对象被记录下来...
我知道你可以在异步循环中使用 Promise.all
,但这是否也适用于 .reduce()
?