openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
28 lines (27 loc) • 732 B
JavaScript
import { s as WEBSOCKET_CLOSE_GRACE_MS } from "./server-constants-CYohpfLc.mjs";
//#region src/gateway/server/connection-transport-close.ts
const closingTransports = /* @__PURE__ */ new WeakSet();
function closeGatewayTransportWithGrace(e, t, n) {
if (closingTransports.has(e)) return;
closingTransports.add(e);
const handleClose = () => {
clearTimeout(r);
e.off("close", handleClose);
closingTransports.delete(e);
};
const terminate = () => {
try {
e.terminate();
} catch {}
};
e.once("close", handleClose);
const r = setTimeout(terminate, WEBSOCKET_CLOSE_GRACE_MS).unref();
try {
e.close(t, n);
} catch {
clearTimeout(r);
terminate();
}
}
//#endregion
export { closeGatewayTransportWithGrace as t };