Skip to content

Instantly share code, notes, and snippets.

@fmarcia
Last active March 2, 2018 21:40
Show Gist options
  • Save fmarcia/09228e74eca842f3469f9495e82ee701 to your computer and use it in GitHub Desktop.
Save fmarcia/09228e74eca842f3469f9495e82ee701 to your computer and use it in GitHub Desktop.
const f = (id, fail) =>
new Promise((y, n) =>
setTimeout(_ => {
console.log(id)
fail ? n() : y()
}, 100)
)
const a = _ =>
new Promise(y =>
f('a1')
.then(_ => f('a2'))
.then(_ => f('a3'))
.then(y)
.catch(y)
)
const b = _ =>
new Promise(y =>
f('b1', 1)
.then(_ => f('b2'))
.then(_ => f('b3'))
.then(y)
.catch(y)
)
const c = _ =>
new Promise(y =>
f('c1')
.then(_ => f('c2', 1))
.then(_ => f('c3'))
.then(y)
.catch(y)
)
{
a()
.then(b)
.then(c)
.then(_ => console.log("success"))
.catch(_ => console.log("unreachable"))
}
a1
a2
a3
b1
c1
c2
success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment