Skip to content

Instantly share code, notes, and snippets.

@lancetw
Created November 3, 2018 05:57
Show Gist options
  • Save lancetw/e30312e4e116080f950b6ab16aff73b0 to your computer and use it in GitHub Desktop.
Save lancetw/e30312e4e116080f950b6ab16aff73b0 to your computer and use it in GitHub Desktop.
const delay = (delay) => () => new Promise((resolve, reject) => setTimeout(resolve, delay))
const main = () => f1().then(f2).catch(f3)
const f1 = () => new Promise((resolve, reject) => ret ? resolve() : reject())
const f2 = () => Promise.resolve('f2')
const f3 = () => Promise.resolve('f3')
let ret = true
const next = () => ret = !ret
const loop = () => main().then(console.log).then(next).then(delay(1000)).then(loop)
loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment