Skip to content

Instantly share code, notes, and snippets.

@yureative
Last active September 14, 2017 09:09
Show Gist options
  • Save yureative/4edb496c0ea65cccf1f3ca1fce9e76fe to your computer and use it in GitHub Desktop.
Save yureative/4edb496c0ea65cccf1f3ca1fce9e76fe to your computer and use it in GitHub Desktop.
Sequential execution of promises
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())
@yureative
Copy link
Author

output

1
2
3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment