Function webSocketAdapter

  • A non-currying variant of withWebSocketAdapter. 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

    An IterableQueue of MessageEvent generated from the WebSocket's "message" events.

    Example

    const ws = new WebSocket('ws://example.com');
    const wsQueue = webSocketAdapter<{ 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.

    Parameters

    • input: WebSocket

      The WebSocket to adapt into an iterable queue.

    Returns ExtendedAsyncIterable<MessageEvent<T>>

Generated using TypeDoc