(
chunk: Uint8Array | string | Socket.CloseEvent
)
| 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> |
no test coverage detected