私はそれが早期に(すべての約束を決意する前にログを)解決して実現した後、以下のコードを書いた:私は正しい順序で解決するために、それを書き換えることができたJS Promises:複数の約定をオブジェクトプロパティとして解決するうえで、きちんとした方法がありますか?
readDirPromise
.then(categoriseFiles)
.then(({movies, series}) => ({
movies: Promise.all(movies.map(movieTasks)),
series: Promise.all(series.map(seriesTasks))
}))
.then((res) => {
console.log(' done!', res)
})
:
readDirPromise
.then(categoriseFiles)
.then((cats) => Promise.all(cats.movies.map(movieTasks)).then((movies) => {
cats.movies = movies
return cats
}))
.then((cats) => Promise.all(cats.series.map(seriesTasks)).then((series) => {
cats.series = series
return cats
}))
.then((res) => {
console.log(' done!', res)
})
が、私は助けることができないが、考える...もっときれいに、より拡張可能な方法はありますか?
@Randy良い点、ああ – daviestar