logoalt Hacker News

gtoweytoday at 2:12 AM2 repliesview on HN

Finally isn't bullet proof. If you execute a promise in a try block and it happens to end without resolving, the finally block will be never be executed. Fun stuff.


Replies

anttiharjutoday at 2:21 AM

defer isn't bullet proof either. I think there's a linter about it and os.Exit.

One can just wrap os.Exit in a helper to get the expected behaviour.

show 1 reply
cute_boitoday at 2:48 AM

I think this is correct behavior.

``` async function run() { try { await new Promise(() => { // The executor function finishes, // but it never calls resolve() or reject(). }); } finally { console.log("cleanup"); } } ```

I never expect cleanup to be logged.