Skip to content

BunSocket

Bun platform socket entry point for Effect sockets.

This module re-exports the shared Node socket constructors for TCP clients, Unix domain socket clients, and adapters from existing Node Duplex streams. It also provides Bun WebSocket layers using globalThis.WebSocket, including a constructor layer and a Socket.Socket layer for a WebSocket URL.

2 exports Added in v4.0.0 Source

Layers

Creates a Socket.Socket layer for a WebSocket URL using Bun's global WebSocket constructor, honoring protocol, open-timeout, and close-code error options.

Signature

declare const layerWebSocket: (
  url: string | Effect<string>,
  options?: {
    readonly closeCodeIsError?: (code: number) => boolean;
    readonly openTimeout?: Duration.Input;
    readonly protocols?: string | Array<string>;
  },
) => Layer.Layer<Socket.Socket, never, never>;

Provides a Socket.WebSocketConstructor backed by Bun's global WebSocket implementation.

Signature

declare const layerWebSocketConstructor: Layer.Layer<Socket.WebSocketConstructor>;