(
options: Net.NetConnectOpts & {
readonly openTimeout?: Duration.DurationInput | undefined
}
)
| 36 | * @category constructors |
| 37 | */ |
| 38 | export const makeNet = ( |
| 39 | options: Net.NetConnectOpts & { |
| 40 | readonly openTimeout?: Duration.DurationInput | undefined |
| 41 | } |
| 42 | ): Effect.Effect<Socket.Socket, Socket.SocketError> => |
| 43 | fromDuplex( |
| 44 | Effect.scopeWith((scope) => { |
| 45 | let conn: Net.Socket | undefined |
| 46 | return Effect.flatMap( |
| 47 | Scope.addFinalizer( |
| 48 | scope, |
| 49 | Effect.sync(() => { |
| 50 | if (!conn) return |
| 51 | if (conn.closed === false) { |
| 52 | if ("destroySoon" in conn) { |
| 53 | conn.destroySoon() |
| 54 | } else { |
| 55 | ;(conn as Net.Socket).destroy() |
| 56 | } |
| 57 | } |
| 58 | }) |
| 59 | ), |
| 60 | () => |
| 61 | Effect.async<Net.Socket, Socket.SocketError, never>((resume) => { |
| 62 | conn = Net.createConnection(options) |
| 63 | conn.once("connect", () => { |
| 64 | resume(Effect.succeed(conn!)) |
| 65 | }) |
| 66 | conn.on("error", (cause) => { |
| 67 | resume(Effect.fail(new Socket.SocketGenericError({ reason: "Open", cause }))) |
| 68 | }) |
| 69 | }) |
| 70 | ) |
| 71 | }), |
| 72 | options |
| 73 | ) |
| 74 | |
| 75 | /** |
| 76 | * @since 1.0.0 |
no test coverage detected