MCPcopy Create free account
hub / github.com/Effect-TS/effect / rawWebSocketClient

Function rawWebSocketClient

packages/platform/node-shared/benchmark/Socket.ts:168–183  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

166}
167
168const rawWebSocketClient = async (url: string): Promise<RawClient> => {
169 const ws = new WebSocket(url)
170 await once(ws, "open")
171 const counter = makeReadCounter()
172 ws.on("message", (data: Buffer) => counter.push(data.length))
173 return {
174 write(frames) {
175 return new Promise<void>((resolve, reject) => {
176 for (let i = 0; i < frames.length - 1; i++) ws.send(frames[i])
177 ws.send(frames[frames.length - 1], (error) => error ? reject(error) : resolve())
178 })
179 },
180 read: counter.read,
181 close: () => ws.terminate()
182 }
183}
184
185const rawDuplexClient = (conn: Duplex): RawClient => {
186 const counter = makeReadCounter()

Callers 1

Socket.tsFile · 0.85

Calls 4

makeReadCounterFunction · 0.85
onMethod · 0.65
pushMethod · 0.65
onceFunction · 0.50

Tested by

no test coverage detected