@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
2 lines (1 loc) • 718 B
JavaScript
;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function d({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((t,n)=>{s.close(u=>u?n(u):t())}),r&&await Promise.race([Promise.resolve().then(r),new Promise((t,n)=>setTimeout(()=>n(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)})}exports.default=d;