Skip to content

Instantly share code, notes, and snippets.

@F1LT3R
Created February 27, 2019 16:54
Show Gist options
  • Save F1LT3R/d28c5fba16c20e290df9690deca7f5fb to your computer and use it in GitHub Desktop.
Save F1LT3R/d28c5fba16c20e290df9690deca7f5fb to your computer and use it in GitHub Desktop.
Awaiting a promise that may throw an error
var wait = (ms) =>
new Promise((resolve, reject) => {
if (Math.random() > 0.5) {
return reject('NOPE!');
}
setTimeout(() => {
resolve('Done!');
}, ms);
});
var doWait = async () => {
const result = await wait(500);
console.log(result);
}
doWait();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment