Skip to content

Instantly share code, notes, and snippets.

@brianloveswords
Created August 20, 2020 22:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save brianloveswords/0b290d387552325a79f9d1b86ec70fab to your computer and use it in GitHub Desktop.
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