diff --git a/deno.json b/deno.json index 22e9bdc..1268509 100644 --- a/deno.json +++ b/deno.json @@ -3,6 +3,7 @@ "tasks": { "cache": "deno cache main.ts server-dev.ts", "server-dev": "deno run -A --unstable \"--watch=static/*.css,static/*.ts,static/*/,routes/,translation/\" server-dev.ts", + "server": "deno run -A --unstable server-run.ts", "test": "deno test --allow-read=./ --allow-net --allow-write=./ --allow-run=tasklist.exe --unstable", "run": "deno run --allow-read=./ --allow-write=./ --allow-run=tasklist.exe --allow-env=DENO_DEPLOYMENT_ID --allow-net --unstable", "compile": "deno compile --allow-read=./ --allow-write=./ --allow-run=tasklist.exe --allow-env=DENO_DEPLOYMENT_ID --allow-net --unstable", diff --git a/routes/api/exit.ts b/routes/api/exit.ts index 2f504b3..4581acb 100644 --- a/routes/api/exit.ts +++ b/routes/api/exit.ts @@ -1,6 +1,8 @@ import { Handlers } from "$fresh/server.ts"; import { parse_bool } from "../../server/parse_form.ts"; import { get_task_manager } from "../../server.ts"; +import { ExitTarget } from "../../signal_handler.ts"; +import { AlreadyClosedError } from "../../task_manager.ts"; export const handler: Handlers = { async POST(req, _ctx) { @@ -11,7 +13,7 @@ export const handler: Handlers = { } catch (_) { null; } - setTimeout(async () => { + const h = async () => { const m = get_task_manager(); const aborted = m.aborted; m.abort(); @@ -20,8 +22,11 @@ export const handler: Handlers = { } if (aborted) return; await m.waiting_unfinished_task(); + ExitTarget.dispatchEvent(new Event("close")); m.close(); - }, 1); + throw new AlreadyClosedError(); + }; + setTimeout(h, 1); return new Response("Aborted."); }, };