From e6d7020fc82d9143a3bfe79135b179721c17c33e Mon Sep 17 00:00:00 2001 From: monoid Date: Thu, 26 Oct 2023 22:10:47 +0900 Subject: [PATCH] fix: signal_listener --- main.ts | 8 +++++++- pages.ts | 15 +++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/main.ts b/main.ts index ae2a76b..e88fd9b 100644 --- a/main.ts +++ b/main.ts @@ -9,9 +9,15 @@ import "$std/dotenv/load.ts"; import { start } from "$fresh/server.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"; +console.log("start"); + +Deno.addSignalListener("SIGINT", () => { + Deno.exit(0); +}); + await start(manifest, { port: 12001, plugins: [twindPlugin(twindConfig)] diff --git a/pages.ts b/pages.ts index f374d6d..9648ba0 100644 --- a/pages.ts +++ b/pages.ts @@ -26,18 +26,25 @@ function watchFile( } } })(); - Deno.addSignalListener("SIGINT", () => { + const closeHandler = () => { watcherRef.close(); - }); + }; + Deno.addSignalListener("SIGINT", closeHandler); + return ()=>{ + Deno.removeSignalListener("SIGINT", closeHandler); + closeHandler(); + } } let pages_meta: PageDescription[] = []; let mtime = 0; +let lastest_disposer = () => {}; export async function get_pages_meta(): Promise<[PageDescription[],number]>{ - if (pages_meta) { + if (pages_meta.length == 0) { pages_meta = await readPagesDescription(); mtime = Date.now(); - watchFile(PAGES_PATH, async () => { + lastest_disposer(); + lastest_disposer = watchFile(PAGES_PATH, async () => { pages_meta = await readPagesDescription(); mtime = Date.now(); });