Skip to content

Instantly share code, notes, and snippets.

@nyawach
Created November 16, 2018 03:09
Show Gist options
  • Save nyawach/872a2b3b4f15739b89ad91a50051bfa4 to your computer and use it in GitHub Desktop.
Save nyawach/872a2b3b4f15739b89ad91a50051bfa4 to your computer and use it in GitHub Desktop.
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()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment