Fix database closed multiple times.

utt part support Ctrl + C
This commit is contained in:
2023-05-23 10:50:56 +08:00
parent 144797f246
commit 5c9712a02c
6 changed files with 69 additions and 12 deletions

View File

@@ -28,3 +28,17 @@ export function add_exit_handler(m: TaskManager) {
});
}
}
export function get_abort_signal(callback?: () => void): AbortSignal {
const a = new AbortController();
const handler = () => {
console.log("Aborted.");
a.abort();
if (callback) callback();
};
Deno.addSignalListener("SIGINT", handler);
if (Deno.build.os !== "windows") {
Deno.addSignalListener("SIGKILL", handler);
}
return a.signal;
}