-
-
Save devsnek/48906a4d44d2dd6afce59014a55a0b30 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
new Promise((resolve, reject) => { | |
const timeout = setTimeout(() => { | |
clearInterval(interval); | |
reject(new Error('timed out')); | |
}, 5000); | |
const interval = setInterval(() => { | |
const x = doSomething(); | |
if (x !== undefined) { | |
clearInterval(interval); | |
clearTimeout(timeout); | |
resolve(x); | |
} | |
}, 1000); | |
}).then((x) => { | |
console.log('x is', x); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment