Created
November 3, 2018 05:57
-
-
Save lancetw/e30312e4e116080f950b6ab16aff73b0 to your computer and use it in GitHub Desktop.
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 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