Skip to content

Instantly share code, notes, and snippets.

@devsnek
Created August 29, 2019 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devsnek/48906a4d44d2dd6afce59014a55a0b30 to your computer and use it in GitHub Desktop.
Save devsnek/48906a4d44d2dd6afce59014a55a0b30 to your computer and use it in GitHub Desktop.
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