Okay Javascript question. Is there a more "elegant" / idiomatic / less ()()y way to do this? // This code doesn't need a completion handler unless it fails (async function() { // Some code using awaits runs here })().catch(e => logError("Oh no!") )
-
Show this thread
-
Replying to @mcclure111
you can use try/catch, "await" turns rejected promises into exceptions
2 replies 0 retweets 2 likes -
Replying to @mountain_ghosts
However there is no await() in this code? (except inside the async function, but since that runs async, the exception propagation will not escape except via catch() ?
1 reply 0 retweets 0 likes -
Replying to @mcclure111
right, picture the function you're referring to as the possibleFailure() in my example
1 reply 0 retweets 0 likes -
Replying to @mountain_ghosts @mcclure111
oh, if you're just calling something that may return a rejected promise, then just go possibleFailure().catch(e => ...)
1 reply 0 retweets 1 like -
Replying to @mountain_ghosts
Ah. OK. I am thinking of my entire async function as "something that may return a rejected promise". But I guess the fact that's not obvious is a sign that this isn't very idiomatic.
2 replies 1 retweet 1 like
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.


