UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

38 lines (37 loc) 949 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(child, { signals = defaultSignals, onSignal } = {}) { const listeners = /* @__PURE__ */ new Map(); for (const signal of signals) { const listener = () => { onSignal?.(signal); try { child.kill(signal); } catch {} }; try { process.on(signal, listener); listeners.set(signal, listener); } catch {} } const detach = () => { for (const [signal, listener] of listeners) process.off(signal, listener); listeners.clear(); }; child.once("exit", detach); child.once("close", detach); return { detach }; } //#endregion export { attachChildProcessBridge as t };