Created
February 27, 2019 16:54
-
-
Save F1LT3R/d28c5fba16c20e290df9690deca7f5fb to your computer and use it in GitHub Desktop.
Awaiting a promise that may throw an error
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
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