MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / makeState

Function makeState

host/network/src/main/state.js:3–25  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1/* Shared handle tables. One `makeState()` per `createWorker` so multiple workers don't share connections. */
2
3export const makeState = () => {
4 const requests = []; // AbortController per in-flight fetch; nulled on completion or abort.
5 const sockets = []; // WebSocket per ws_open; nulled on close.
6 const sseSources = []; // EventSource per sse_open; nulled on close.
7
8 const allocSocket = (ws) => { sockets.push(ws); return sockets.length - 1; };
9 const socket = (h) => {
10 if (h < 0 || h >= sockets.length || sockets[h] === null) {
11 throw new Error('invalid socket handle: ' + h);
12 }
13 return sockets[h];
14 };
15
16 const allocSse = (es) => { sseSources.push(es); return sseSources.length - 1; };
17 const sse = (h) => {
18 if (h < 0 || h >= sseSources.length || sseSources[h] === null) {
19 throw new Error('invalid sse handle: ' + h);
20 }
21 return sseSources[h];
22 };
23
24 return { requests, sockets, sseSources, allocSocket, socket, allocSse, sse };
25};

Callers 1

networkFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected