Performance: Signal handling and process management
This affects how efficiently a Deno application responds to system signals and manages child processes, impacting responsiveness and resource usage.
Deno.addSignalListener("SIGINT", async () => { await cleanupAsync(); console.log("Cleanup done"); Deno.exit(); }); async function cleanupAsync() { // non-blocking cleanup logic await new Promise(resolve => setTimeout(resolve, 100)); }
Deno.addSignalListener("SIGINT", () => { // heavy synchronous cleanup for (let i = 0; i < 1e9; i++) {} console.log("Cleanup done"); Deno.exit(); });
| Pattern | Event Loop Blocking | Resource Usage | Responsiveness Impact | Verdict |
|---|---|---|---|---|
| Blocking synchronous signal handler | Blocks event loop | Low immediate, but delays cleanup | High delay in input responsiveness | [X] Bad |
| Async signal handler with awaited cleanup | Non-blocking | Efficient resource use | Fast response to signals | [OK] Good |
| Ignoring child process completion | No direct block | Leads to resource leaks | Potential slowdowns over time | [X] Bad |
| Awaiting and closing child processes | Non-blocking | Proper resource cleanup | Stable and responsive | [OK] Good |
const sig = Deno.signal(Deno.Signal.SIGINT);
for await (const _ of sig) {
console.log('Signal received');
sig.dispose();
}const p = Deno.run({ cmd: ["ls", "-l"] });
p.status().then(status => {
console.log(`Process exited with code ${status.code}`);
});
p.close();Pass the test and this pattern moves unknown