Created
October 11, 2018 03:16
-
-
Save KK7NZY/c74618d32dc7ec9e87c88b9f9768c3b1 to your computer and use it in GitHub Desktop.
Promise Sequence Example
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
function transaction(delay) { | |
return new Promise((resolve, reject) => { | |
console.log(delay, "seconds"); | |
setTimeout(() => resolve(delay), delay * 1000); | |
}); | |
} | |
function main() { | |
return [5, 4, 3, 2, 1].reduce((prev, next) => prev.then(() => transaction(next)), Promise.resolve()); | |
} | |
if (require.main === module) { | |
main().then(() => console.log("Finished")); | |
console.log("Promise Sequence Example"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment