(
options: Net.NetConnectOpts & {
readonly openTimeout?: Duration.Input | undefined
/**
* Maximum chunks per pull. Defaults to 4096 unless a positive safe integer or Infinity is supplied.
* Use Infinity for unbounded batching.
*/
readonly chunkSize?: number | undefined
}
)
| 85 | * @since 4.0.0 |
| 86 | */ |
| 87 | export const makeNet = ( |
| 88 | options: Net.NetConnectOpts & { |
| 89 | readonly openTimeout?: Duration.Input | undefined |
| 90 | /** |
| 91 | * Maximum chunks per pull. Defaults to 4096 unless a positive safe integer or Infinity is supplied. |
| 92 | * Use Infinity for unbounded batching. |
| 93 | */ |
| 94 | readonly chunkSize?: number | undefined |
| 95 | } |
| 96 | ): Effect.Effect<Socket.Socket> => |
| 97 | fromDuplex( |
| 98 | Effect.contextWith((context: Context.Context<Scope.Scope>) => { |
| 99 | let conn: Net.Socket | undefined |
| 100 | let isOpen = false |
| 101 | return Effect.flatMap( |
| 102 | Scope.addFinalizer( |
| 103 | Context.get(context, Scope.Scope), |
| 104 | Effect.sync(() => { |
| 105 | if (!conn) return |
| 106 | closeSocket(conn, isOpen) |
| 107 | }) |
| 108 | ), |
| 109 | () => |
| 110 | Effect.callback<Net.Socket, Socket.SocketError, never>((resume) => { |
| 111 | conn = Net.createConnection(options) |
| 112 | conn.once("connect", () => { |
| 113 | isOpen = true |
| 114 | resume(Effect.succeed(conn!)) |
| 115 | }) |
| 116 | conn.on("error", (cause: Error) => { |
| 117 | resume(Effect.fail( |
| 118 | new Socket.SocketError({ |
| 119 | reason: new Socket.SocketOpenError({ kind: "Unknown", cause }) |
| 120 | }) |
| 121 | )) |
| 122 | }) |
| 123 | }) |
| 124 | ) |
| 125 | }), |
| 126 | options |
| 127 | ) |
| 128 | |
| 129 | /** |
| 130 | * Adapts a Node `Duplex` into a `Socket.Socket`. |
no test coverage detected