mise API - v0.0.0
    Preparing search index...

    Class RequestBroker<TReply>

    A broker for one kind of correlated request over a WebSocket.

    Guarantees, uniformly for every kind: an id unique within the broker, a rejection when the origin socket closes before answering, removal of the close listener once settled (no per-request listener leak), and settles accepted only from the socket the request was sent to (no cross-surface answering).

    const prompts = new RequestBroker<string>('p', 'surface disconnected before answering');
    const answer = await prompts.open(surface.socket, (promptId) =>
    send(surface.socket, { type: 'prompt', promptId, message, hidden }));
    // on a promptAnswer message:
    prompts.settle(socket, message.promptId, message.answer);

    Type Parameters

    • TReply
    Index
    • Rejects a pending request with a reported failure. Ignored when the id is unknown or the failure arrives from a socket other than the request's origin.

      Parameters

      • socket: WebSocket

        The socket the failure arrived on.

      • id: string

        The correlation id.

      • reason: string

        Human-readable failure reason.

      Returns void

    • Opens a request with a generated id: registers the pending entry and its close guard, then invokes send with the id to put the request on the wire.

      Parameters

      • origin: WebSocket

        The socket the request goes to; only it may settle.

      • send: (id: string) => void

        Callback that transmits the request, given the new id.

      Returns Promise<TReply>

      The correlated reply.

      With the broker's disconnect reason when the origin closes before answering, or the reason given to fail.

    • Opens a request under a caller-supplied id, for callers that already correlate ids externally (the remote client's execute/complete counter).

      Parameters

      • id: string

        The correlation id to register.

      • origin: WebSocket

        The socket the request goes to; only it may settle.

      • send: (id: string) => void

        Callback that transmits the request, given the id.

      Returns Promise<TReply>

      The correlated reply.

      As open.

    • Whether this origin already has a request in flight.

      Some requests may be concurrent and some may not: a surface can render two pipeline segments at once, but it cannot sensibly be asked two questions at once. The broker reports the fact; what to do about it belongs to the caller.

      Parameters

      • origin: WebSocket

        The socket to ask about.

      Returns boolean

      True when a request opened on that socket is still awaiting a reply.

    • Resolves a pending request with its reply. Ignored when the id is unknown or the reply arrives from a socket other than the request's origin.

      Parameters

      • socket: WebSocket

        The socket the reply arrived on.

      • id: string

        The correlation id.

      • reply: TReply

        The reply value.

      Returns void