Hong Minhee
Hong Minhee2y ago

How can I let my program keep running even if it receives SIGINT?

I succeeded to write a program to handle SIGINT using Deno.addSignalListener("SIGINT", ...) API, but Deno always exits when it receives a SIGINT whether I put Deno.exit() inside the signal handler or not. [Edit: It was my mistake. Deno keeps running if a signal handler was registered.] I just want my program to reload the configuration file instead of terminating when it receives SIGINT. Is there any way to do it?
4 Replies
AapoAlas
AapoAlas2y ago
You can stop a program from existing by using beforeunload listener: https://deno.land/manual@v1.29.4/runtime/program_lifecycle#program-lifecycle
Deno
Program Lifecycle | Manual | Deno
Deno supports browser compatible lifecycle events:
AapoAlas
AapoAlas2y ago
If you call preventDefault() on the event it will, well, prevent the default handling from occurring which is to close the program.
Hong Minhee
Hong Minhee2y ago
Sorry, it was my mistake. I tested again with a minimal example, and Deno apparently keeps running even if it receives SIGINT once after I registered a signal handler.
AapoAlas
AapoAlas2y ago
Ah, okay.