Function withWebSocketAdapter

  • Creates a curried function that takes a WebSocket as an input and returns an async iterable queue that generates values from the WebSocket's "message" events. Automatically marks the queue as sealed when the WebSocket is closed.

    Returns

    A function that takes a WebSocket as input and returns an IterableQueue of MessageEvent.

    Example

    const ws = new WebSocket('ws://example.com');
    const wsQueue = withWebSocketAdapter<{ message: string }>()(ws);

    (async () => {
    for await (const event of wsQueue) {
    console.log(event.data); // Logs WebSocket messages as they are received
    }
    })();

    Type Parameters

    • T

      The type of data contained in the WebSocket messages.

    Returns ((input: WebSocket) => ExtendedAsyncIterable<MessageEvent<T>>)

Generated using TypeDoc