PendingRpcSubscriptionsRequest

type PendingRpcSubscriptionsRequest<TNotification> = object;

Pending subscriptions are the result of calling a supported method on a RpcSubscriptions object. They encapsulate all of the information necessary to make the subscription without actually making it.

Calling the `subscribe(options)` method on a PendingRpcSubscriptionsRequest<TNotification> will trigger the subscription and return a promise for an async iterable that vends TNotifications.

Calling the `reactiveStore()` method will return a ReactiveStreamStore compatible with useSyncExternalStore, Svelte stores, and other reactive primitives. The returned store is in status: 'idle'; the caller is responsible for invoking ReactiveStreamStore.connect | `connect()` to open the underlying stream. Attach a caller-provided cancellation source via ReactiveStreamStore.withSignal | `withSignal()`.

Type Parameters

Type Parameter
TNotification

Methods

reactiveStore()

reactiveStore(): ReactiveStreamStore<TNotification>;

Synchronously returns a ReactiveStreamStore that holds the latest notification. Compatible with useSyncExternalStore and other reactive primitives that expect a { subscribe, getUnifiedState } contract. The returned store is in status: 'idle' — call ReactiveStreamStore.connect | `connect()` to open the subscription; a follow-up connect() after an error reopens it. Attach a caller-provided cancellation source via ReactiveStreamStore.withSignal | `withSignal()`.

Returns

ReactiveStreamStore<TNotification>

Example

const store = rpc.accountNotifications(address).reactiveStore();
// Per-connection timeout — fresh clock per attempt:
store.withSignal(AbortSignal.timeout(30_000)).connect();
// React — the unified snapshot has stable identity per update.
const state = useSyncExternalStore(store.subscribe, store.getUnifiedState);
if (state.status === 'error') return <ErrorMessage error={state.error} onRetry={store.connect} />;
if (state.status === 'loading' || state.status === 'idle') return <Spinner />;
return <View data={state.data} />;

subscribe()

subscribe(options): Promise<AsyncIterable<TNotification, any, any>>;

Triggers the subscription and returns a promise for an async iterable of notifications. Use for await...of to consume notifications as they arrive. Abort the signal to unsubscribe.

Parameters

ParameterType
optionsRpcSubscribeOptions

Returns

Promise<AsyncIterable<TNotification, any, any>>

Example

const notifications = await rpc.accountNotifications(address).subscribe({ abortSignal });
for await (const notification of notifications) {
    console.log('Account changed:', notification);
}

On this page