UNPKG

@sigiljs/sigil

Version:

TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating

28 lines (27 loc) 849 B
function f({ server: s, cleanup: r, timeoutMs: a = 1e4 }) { let i = !1; const c = (e) => setTimeout(() => process.exit(e), 100).unref(), o = async (e) => { if (!i) { i = !0; try { s && await new Promise((n, t) => { s.close((u) => u ? t(u) : n()); }), r && await Promise.race([ Promise.resolve().then(r), new Promise((n, t) => setTimeout(() => t(new Error("cleanup timeout")), a)) ]), c(e); } catch { c(1); } } }, l = ["SIGINT", "SIGTERM", "SIGQUIT", "SIGHUP", "SIGUSR2"]; for (const e of l) process.on(e, () => o(0)); process.on("uncaughtException", (e) => { console.error("Uncaught exception:", e), o(1); }), process.on("unhandledRejection", (e) => { console.error("Unhandled rejection:", e), o(1); }); } export { f as default };