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

Function write

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

Source from the content-addressed store, hash-verified

475 })
476
477 const write = (
478 chunk: Uint8Array | string | Socket.CloseEvent
479 ): Effect.Effect<void, Socket.SocketError> =>
480 Effect.suspend(() => {
481 if (terminalError !== undefined) return Effect.fail(terminalError)
482 const conn = currentSocket
483 if (conn === undefined) return latch.whenOpen(write(chunk))
484 if (Socket.isCloseEvent(chunk)) {
485 conn.destroy(chunk.code > 1000 ? new Error(`closed with code ${chunk.code}`) : undefined)
486 return Effect.void
487 }
488 try {
489 return conn.write(chunk) ? Effect.void : awaitDrain(conn)
490 } catch (cause) {
491 return Effect.fail(
492 new Socket.SocketError({
493 reason: new Socket.SocketWriteError({ cause })
494 })
495 )
496 }
497 })
498
499 const writeAll = (
500 chunks: Arr.NonEmptyReadonlyArray<Uint8Array | string>

Callers 2

nodeWriteFactoryFunction · 0.70
writeOnceMethod · 0.70

Calls 5

awaitDrainFunction · 0.85
whenOpenMethod · 0.80
failMethod · 0.65
writeMethod · 0.65
destroyMethod · 0.45

Tested by

no test coverage detected