Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Promise Sequence Example
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
You can’t perform that action at this time.