Handle OS Signals
- Deno.addSignalListener() can be used to capture and monitor OS signals.
- can be used to stop watching the signal.
APIs for handling OS signals are modelled after already familiar and APIs.
⚠️ Note that listening for OS signals doesn’t prevent event loop from finishing, ie. if there are no more pending async operations the process will exit.
Run with:
You can use Deno.removeSignalListener()
function to unregister previously
added signal handler.
deno run signal_listeners.ts
If you prefer to handle signals using an async iterator, you can use
API available in deno_std
:
Run with:
deno run async_iterator_signal.ts