fix: signal_listener

This commit is contained in:
monoid 2023-10-26 22:10:47 +09:00
parent 32c1458a9c
commit e6d7020fc8
2 changed files with 18 additions and 5 deletions

View File

@ -9,9 +9,15 @@ import "$std/dotenv/load.ts";
import { start } from "$fresh/server.ts"; import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts"; import manifest from "./fresh.gen.ts";
import twindPlugin from "$fresh/plugins/twind.ts"; import twindPlugin from "$fresh/plugins/twindv1.ts";
import twindConfig from "./twind.config.ts"; import twindConfig from "./twind.config.ts";
console.log("start");
Deno.addSignalListener("SIGINT", () => {
Deno.exit(0);
});
await start(manifest, { await start(manifest, {
port: 12001, port: 12001,
plugins: [twindPlugin(twindConfig)] plugins: [twindPlugin(twindConfig)]

View File

@ -26,18 +26,25 @@ function watchFile(
} }
} }
})(); })();
Deno.addSignalListener("SIGINT", () => { const closeHandler = () => {
watcherRef.close(); watcherRef.close();
}); };
Deno.addSignalListener("SIGINT", closeHandler);
return ()=>{
Deno.removeSignalListener("SIGINT", closeHandler);
closeHandler();
}
} }
let pages_meta: PageDescription[] = []; let pages_meta: PageDescription[] = [];
let mtime = 0; let mtime = 0;
let lastest_disposer = () => {};
export async function get_pages_meta(): Promise<[PageDescription[],number]>{ export async function get_pages_meta(): Promise<[PageDescription[],number]>{
if (pages_meta) { if (pages_meta.length == 0) {
pages_meta = await readPagesDescription(); pages_meta = await readPagesDescription();
mtime = Date.now(); mtime = Date.now();
watchFile(PAGES_PATH, async () => { lastest_disposer();
lastest_disposer = watchFile(PAGES_PATH, async () => {
pages_meta = await readPagesDescription(); pages_meta = await readPagesDescription();
mtime = Date.now(); mtime = Date.now();
}); });