Last active
May 29, 2023 03:00
-
-
Save yongjun21/3f4e8bf66e1ea57c49376769719c8ac4 to your computer and use it in GitHub Desktop.
Simple Promise.waterfall implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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