Skip to content

Instantly share code, notes, and snippets.

@KK7NZY
Created October 11, 2018 03:16
Show Gist options
  • Save KK7NZY/c74618d32dc7ec9e87c88b9f9768c3b1 to your computer and use it in GitHub Desktop.
Save KK7NZY/c74618d32dc7ec9e87c88b9f9768c3b1 to your computer and use it in GitHub Desktop.
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