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

Function write

packages/effect/src/socket/Socket.ts:1199–1214  ·  view source on GitHub ↗
(chunk: Uint8Array | string | CloseEvent)

Source from the content-addressed store, hash-verified

1197 : connect
1198
1199 const write = (chunk: Uint8Array | string | CloseEvent): Effect.Effect<void, SocketError> =>
1200 Effect.suspend(() => {
1201 if (terminalError !== undefined) return Effect.fail(terminalError)
1202 const ws = currentWS
1203 if (ws === undefined) return latch.whenOpen(write(chunk))
1204 try {
1205 if (isCloseEvent(chunk)) {
1206 ws.close(chunk.code, chunk.reason)
1207 } else {
1208 ws.send(chunk as string | Uint8Array<ArrayBuffer>)
1209 }
1210 return Effect.void
1211 } catch (cause) {
1212 return Effect.fail(new SocketError({ reason: new SocketWriteError({ cause }) }))
1213 }
1214 })
1215 const writeAll = (
1216 chunks: NonEmptyReadonlyArray<Uint8Array | string>
1217 ): Effect.Effect<void, SocketError> =>

Callers

nothing calls this directly

Calls 10

isCloseEventFunction · 0.85
closeErrorFunction · 0.85
getWriterFunction · 0.85
whenOpenMethod · 0.80
encodeMethod · 0.80
failMethod · 0.65
closeMethod · 0.65
sendMethod · 0.65
writeMethod · 0.65
syncMethod · 0.45

Tested by

no test coverage detected