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

Function processData

packages/effect/src/rpc/RpcClient.ts:1364–1400  ·  view source on GitHub ↗
(data: Uint8Array | string)

Source from the content-addressed store, hash-verified

1362 }
1363
1364 const processData = (data: Uint8Array | string): Effect.Effect<void> => {
1365 try {
1366 const responses = parser.decode(data) as Array<FromServerEncoded>
1367 if (responses.length === 0) return Effect.void
1368 pinger.onFrame()
1369 let i = 0
1370 return Effect.whileLoop({
1371 while: () => i < responses.length,
1372 body: () => {
1373 const response = responses[i++]
1374 if (response._tag === "Pong") return Effect.void
1375 if (Object.hasOwn(response, "requestId")) {
1376 const requestId = (response as FromServerEncoded & { readonly requestId: string | number }).requestId
1377 const clientId = requestClientMap.get(requestId)
1378 if (clientId !== undefined) {
1379 if (response._tag === "Exit") {
1380 requestClientMap.delete(requestId)
1381 }
1382 return writeResponse(clientId, response)
1383 }
1384 }
1385 return broadcast(response)
1386 },
1387 step: constVoid
1388 })
1389 } catch (defect) {
1390 return broadcast({
1391 _tag: "ClientProtocolError",
1392 error: new RpcClientError({
1393 reason: new RpcClientDefect({
1394 message: "Error decoding message",
1395 cause: defect
1396 })
1397 })
1398 })
1399 }
1400 }
1401
1402 yield* Effect.suspend(() => {
1403 parser = serialization.makeUnsafe()

Callers 1

makeProtocolSocketFunction · 0.70

Calls 5

writeResponseFunction · 0.85
broadcastFunction · 0.70
getMethod · 0.65
deleteMethod · 0.65
decodeMethod · 0.45

Tested by

no test coverage detected