Skip to content

NodeSocket.ts

Node socket adapters for Effect sockets.

This module opens node:net connections or wraps existing Node Duplex streams and presents them as Socket.Socket values, socket channels, or layers. It also exposes the current underlying NetSocket service for code running inside a socket handler and re-exports the ws package namespace.

Since v4.0.0



Adapts a Node Duplex into a Socket.Socket, wiring data events to socket handlers, providing a scoped writer, and mapping open, read, write, and close failures to SocketError.

Signature

declare const fromDuplex: <RO>(
open: Effect.Effect<Duplex, Socket.SocketError, RO>,
options?: { readonly openTimeout?: Duration.Input | undefined }
) => Effect.Effect<Socket.Socket, never, Exclude<RO, Scope.Scope>>

Source

Since v4.0.0

Opens a Node TCP connection as an Effect socket.

When to use

Use to create a scoped Socket.Socket from Node net.createConnection.

Details

Supports openTimeout and closes or destroys the underlying socket when the enclosing scope is finalized.

Signature

declare const makeNet: (
options: Net.NetConnectOpts & { readonly openTimeout?: Duration.Input | undefined }
) => Effect.Effect<Socket.Socket>

Source

Since v4.0.0

Creates a Channel over a TCP socket, reading arrays of Uint8Array chunks and writing arrays of bytes, strings, or socket close events.

Signature

declare const makeNetChannel: <IE = never>(
options: Net.NetConnectOpts
) => Channel.Channel<
Array.NonEmptyReadonlyArray<Uint8Array>,
Socket.SocketError | IE,
void,
Array.NonEmptyReadonlyArray<Uint8Array | string | Socket.CloseEvent>,
IE
>

Source

Since v4.0.0

Provides a Socket.Socket by opening a TCP connection with the supplied Node net connection options.

Signature

declare const layerNet: (options: Net.NetConnectOpts) => Layer.Layer<Socket.Socket, Socket.SocketError>

Source

Since v4.0.0

Re-exports all named exports from the “ws” module as NodeWS.

Signature

export * as NodeWS from "ws"

Source

Since v4.0.0

Service tag for the underlying Node net.Socket associated with the current socket connection.

Signature

declare class NetSocket

Source

Since v4.0.0