One can just wrap os.Exit in a helper to get the expected behaviour.
``` 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.
Try X finally dispose of all resources. X, defer clean up X. Or how about just X and cleanup is done automatically, with the author of the resources deciding what is needed to clean X up.
There isn't any way to forget to drop a resource if you have RAII.
RAII doesn't really fit into every language because they don't all have deterministic destructors/finalizers and objects with scoped lifetimes. Sometimes you only have one but not the other and you definitely need both.
It's way easier to use, much clear, less typing, more predictable runtime behavior.
RAII... terrible name, great concept!
defer is the thing I miss the most coming from Go