CodyCC
Denoβ€’13mo agoβ€’
4 replies
CodyC

Reliable pattern for cleaning up resources as process exists?

I'm using Explicit Resource Management (await using resource = ...), but [Symbol.asyncDispose] doesn't get called if my program is killed with SIGINT or other signals. Is there a known/good pattern for making sure some resource gets cleaned up, even if the process is dying?

I'm familiar with window.onunload, but since that's a global, it feels unreliable to rely on, since anything else in my dependencies might overwrite it during a lengthy runtime. I may also have more than one thing that I want to clean up. (never mind, unload doesn't fire during SIGINT)

I also know about Deno.addSignalListener() but there are an awful lot of signals I'd need to listen to.
Was this page helpful?