UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

42 lines (41 loc) • 860 B
import process from "node:process"; //#region src/process/child-process-bridge.ts const defaultSignals = process.platform === "win32" ? [ "SIGTERM", "SIGINT", "SIGBREAK" ] : [ "SIGTERM", "SIGINT", "SIGHUP", "SIGQUIT" ]; /** Forwards process termination signals to a child and detaches on terminal lifecycle events. */ function attachChildProcessBridge(e, t) { const n = /* @__PURE__ */ new Map(); let r = false; for (const i of defaultSignals) { const listener = () => { if (r) return; t?.(i); try { e.kill(i); } catch {} }; try { process.on(i, listener); n.set(i, listener); } catch {} } const detach = () => { for (const [e, t] of n) process.off(e, t); n.clear(); }; e.once("exit", () => { r = true; }); e.once("close", detach); return { detach }; } //#endregion export { attachChildProcessBridge as t };