NodeSocket.ts
NodeSocket.ts overview
Section titled “NodeSocket.ts overview”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
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”fromDuplex
Section titled “fromDuplex”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>>Since v4.0.0
makeNet
Section titled “makeNet”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>Since v4.0.0
makeNetChannel
Section titled “makeNetChannel”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>Since v4.0.0
layers
Section titled “layers”layerNet
Section titled “layerNet”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>Since v4.0.0
re-exports
Section titled “re-exports”NodeWS (namespace export)
Section titled “NodeWS (namespace export)”Re-exports all named exports from the “ws” module as NodeWS.
Signature
export * as NodeWS from "ws"Since v4.0.0
services
Section titled “services”NetSocket (class)
Section titled “NetSocket (class)”Service tag for the underlying Node net.Socket associated with the current
socket connection.
Signature
declare class NetSocketSince v4.0.0