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

Function write

packages/platform/node-shared/src/NodeSocket.ts:203–221  ·  view source on GitHub ↗
(chunk: Uint8Array | string | Socket.CloseEvent)

Source from the content-addressed store, hash-verified

201 )
202
203 const write = (chunk: Uint8Array | string | Socket.CloseEvent) =>
204 latch.whenOpen(Effect.callback<void, Socket.SocketError>((resume) => {
205 const conn = currentSocket!
206 if (Socket.isCloseEvent(chunk)) {
207 conn.destroy(chunk.code > 1000 ? new Error(`closed with code ${chunk.code}`) : undefined)
208 return resume(Effect.void)
209 }
210 currentSocket!.write(chunk, (cause) => {
211 resume(
212 cause
213 ? Effect.fail(
214 new Socket.SocketError({
215 reason: new Socket.SocketWriteError({ cause: cause! })
216 })
217 )
218 : Effect.void
219 )
220 })
221 }))
222
223 const writer = Effect.acquireRelease(
224 Effect.succeed(write),

Callers

nothing calls this directly

Calls 4

whenOpenMethod · 0.80
writeMethod · 0.65
resumeFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected