Skip to content

Instantly share code, notes, and snippets.

@yongjun21
Last active May 29, 2023 03:00
Show Gist options
  • Save yongjun21/3f4e8bf66e1ea57c49376769719c8ac4 to your computer and use it in GitHub Desktop.
Save yongjun21/3f4e8bf66e1ea57c49376769719c8ac4 to your computer and use it in GitHub Desktop.
Simple Promise.waterfall implementation
Promise.waterfall = function (array, invoke) {
let pending = Promise.resolve()
const results = []
for (const item of array) {
pending = pending
.then(() => invoke(item, i))
.then(result => results.push(result))
}
return pending.then(() => results)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment