nyawach
11/16/2018 - 3:09 AM

Promiesの逐次実行

Promiesの逐次実行

const series = promises => new Promise((resolve, reject) => {
  let len = promises.length
  let i = 0
  let results = []
  const doPromise = () =>
    promises[i]()
      .then(res => {
        i++
        results.push(res)
        return i < len ? doPromise() : resolve(results)
      })
  doPromise()
})