| 164 | ) |
| 165 | |
| 166 | const write = (chunk: Uint8Array | string | Socket.CloseEvent) => |
| 167 | latch.whenOpen(Effect.async<void, Socket.SocketError>((resume) => { |
| 168 | const conn = currentSocket! |
| 169 | if (Socket.isCloseEvent(chunk)) { |
| 170 | conn.destroy(chunk.code > 1000 ? new Error(`closed with code ${chunk.code}`) : undefined) |
| 171 | return resume(Effect.void) |
| 172 | } |
| 173 | currentSocket!.write(chunk, (cause) => { |
| 174 | resume( |
| 175 | cause |
| 176 | ? Effect.fail(new Socket.SocketGenericError({ reason: "Write", cause })) |
| 177 | : Effect.void |
| 178 | ) |
| 179 | }) |
| 180 | })) |
| 181 | |
| 182 | const writer = Effect.acquireRelease( |
| 183 | Effect.succeed(write), |