MCPcopy
hub / github.com/Effect-TS/effect / makeNet

Function makeNet

packages/platform-node-shared/src/NodeSocket.ts:38–73  ·  view source on GitHub ↗
(
  options: Net.NetConnectOpts & {
    readonly openTimeout?: Duration.DurationInput | undefined
  }
)

Source from the content-addressed store, hash-verified

36 * @category constructors
37 */
38export 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

Callers 2

makeNetChannelFunction · 0.85
layerNetFunction · 0.85

Calls 6

syncMethod · 0.80
destroyMethod · 0.80
fromDuplexFunction · 0.70
addFinalizerMethod · 0.65
failMethod · 0.65
resumeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…