MCPcopy Index your code
hub / github.com/coder/mux / closeWebSocketSafely

Function closeWebSocketSafely

src/browser/contexts/API.tsx:84–93  ·  view source on GitHub ↗
(ws: WebSocket)

Source from the content-addressed store, hash-verified

82const noopConnectionControl = (_token?: string) => undefined;
83
84function closeWebSocketSafely(ws: WebSocket) {
85 try {
86 // readyState: 0 = CONNECTING, 1 = OPEN, 2 = CLOSING, 3 = CLOSED
87 if (ws.readyState === 2 || ws.readyState === 3) return;
88 ws.close();
89 } catch {
90 // Some browsers throw if close() is called while already closing/closed.
91 // Since our cleanup can be invoked from multiple code paths, treat close as idempotent.
92 }
93}
94
95function isRecord(value: unknown): value is Record<string, unknown> {
96 return typeof value === "object" && value !== null;

Callers 1

createBrowserClientFunction · 0.85

Calls 1

closeMethod · 0.65

Tested by

no test coverage detected