function shutdown
shutdown(
state: DaemonState,
reason: string,
exit?: () => void
): Promise<void>

Tears the daemon down: notifies pending clients, removes the on-disk liveness markers, closes the browser/esbuild within a bounded grace, then exits. Idempotent via state.shuttingDown. exit is injectable only so the shutdown ordering can be tested without killing the test process; production always uses the default. See test/commands/daemon-shutdown-test.ts.

import type * as Server from './server.ts';

// Defined, not invoked: closes the socket server and browser, then exits the process.
async function stopOnSignal(stop: typeof Server.shutdown, state: Parameters<typeof Server.shutdown>[0]) {
  await stop(state, 'SIGTERM');
}

Parameters

reason: string
optional
exit: () => void

Return Type

Promise<void>

Usage

import { shutdown } from "lib/commands/daemon/server.ts";