그래서 같은) 비동기를 통합하는 문제도/.reduce (함께 기다리고있을 것 같다 :스크립트 배열 .reduce와 비동기/AWAIT
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()
에 해당합니까?
감사를 말 . 내가하고있는 일에 대해 단순한 for 루프를 사용하여 끝내었지만, 코드와 같은 줄 이었지만 읽는 것이 훨씬 쉬웠다. ... –
'reduce'의'initialValue'는'Promise ', 그러나 그것은 대부분의 경우에 의도를 분명히 할 것이다. – EECOLOR
@EECOLOR 그래야합니다. 나는 평범한 가치를 약속으로 던지기를 정말로 싫어한다. – Bergi