Last active
September 14, 2017 09:09
-
-
Save yureative/4edb496c0ea65cccf1f3ca1fce9e76fe to your computer and use it in GitHub Desktop.
Sequential execution of promises
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
const a = (n, timeout) => | |
() => | |
new Promise((resolve, reject) => { | |
setTimeout( | |
() => { | |
console.log(n) | |
resolve(n) | |
}, | |
timeout) | |
}) | |
const promises = [ | |
a(1, 300), | |
a(2, 200), | |
a(3, 100) | |
] | |
promises.reduce( | |
(prev, current) => prev.then(current), | |
Promise.resolve()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output