Sanity Library Reference Docs
    Preparing search index...

    Interface MessageBusHost

    The host's connection to the bus.

    State reaches an application only through MessageBusClient.emit. There is no broadcast: sending the same value to everyone is a loop over connections, and giving a new connection the current values is done when it appears there, as an SSE server writes a snapshot to each new client.

    interface MessageBusHost {
        connections: Observable<MessageBusClient>;
        disconnect(): void;
        emit<K extends EventTopic>(
            type: K,
            ...rest: PayloadOf<K> extends void
                ? [payload?: void, options?: MessageBusEmitOptions]
                : [payload: PayloadOf<K>, options?: MessageBusEmitOptions],
        ): MessageBusEmitResult<ReplyOf<K>>;
        query<K extends StateTopic>(
            type: K,
            options?: MessageBusQueryOptions,
        ): Promise<ValueOf<K>>;
        subscribe<K extends EventTopic>(
            type: K,
            handler: (message: MessageBusMessage<PayloadOf<K>, ReplyOf<K>>) => void,
            options?: MessageBusAbortOptions,
        ): void;
        subscribe<K extends StateTopic>(
            type: K,
            handler: (value: ValueOf<K>) => void,
            options?: MessageBusAbortOptions,
        ): void;
        subscribe<K extends StateTopic>(type: K): MessageBusStateSource<ValueOf<K>>;
        subscribe<K extends EventTopic>(type: K): Observable<PayloadOf<K>>;
    }

    Hierarchy (View Summary)

    Index

    Properties

    connections: Observable<MessageBusClient>

    Every open connection other than this one first, then each new one as it joins. The same MessageBusClient object is handed out for a connection across subscriptions, so it can be kept in a Set. A connection stays listed until it calls disconnect(); the SDK does that when the owning SanityInstance is disposed.

    Methods

    • Tears down this connection: pending requests reject ABORTED, subscriptions complete, and later emit, query, and subscribe calls fail with ABORTED. Siblings and the shared bus are untouched.

      Returns void