Created
August 20, 2020 22:34
-
-
Save brianloveswords/0b290d387552325a79f9d1b86ec70fab 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
function cursedPromise() { | |
return new Promise(resolve => { | |
if (Math.random() > 0.5) resolve(); | |
}); | |
} | |
async function main() { | |
await cursedPromise(); | |
console.log("after await"); | |
return "ok"; | |
} | |
// Half the time this will print: | |
// | |
// after await | |
// result: ok | |
// finally! | |
// | |
// and the other half the time NOTHING AT ALL | |
main() | |
.then( | |
result => console.error("result:", result), | |
error => console.error("error:", error), | |
) | |
.finally(() => console.log("finally!")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment