PendingRpcRequest

type PendingRpcRequest<TResponse> = object;

Pending requests are the result of calling a supported method on a Rpc object. They encapsulate all of the information necessary to make the request without actually making it.

Calling the `send(options)` method on a PendingRpcRequest<TResponse> will trigger the request and return a promise for TResponse.

Calling the `reactiveStore()` method will return a ReactiveActionStore compatible with useSyncExternalStore, Svelte stores, and other reactive primitives. The store is returned in the idle state — call dispatch() to fire the request.

Type Parameters

Type Parameter
TResponse

Methods

reactiveStore()

reactiveStore(): ReactiveActionStore<[], TResponse>;

Synchronously returns a ReactiveActionStore in the idle state, ready to dispatch the underlying request. Compatible with useSyncExternalStore and other reactive primitives that expect a { subscribe, getState } contract. Call dispatch() to fire the request (again on retry), or reset() to abort the in-flight call and return to status: 'idle'.

Unlike PendingRpcRequest.send, this method does not fire the request on creation — the caller is responsible for dispatching. This makes signal handling uniform: attach a caller-provided cancellation source per dispatch via store.withSignal(signal).dispatch(...).

Returns

ReactiveActionStore<[], TResponse>

Example

const store = rpc.getAccountInfo(address).reactiveStore();
store.withSignal(AbortSignal.timeout(5_000)).dispatch(); // fire with a per-attempt timeout
const state = useSyncExternalStore(store.subscribe, store.getState);
if (state.status === 'error') return <ErrorMessage error={state.error} onRetry={store.dispatch} />;
if (state.status === 'running' && !state.data) return <Spinner />;
return <View data={state.data!} />;

send()

send(options?): Promise<TResponse>;

Parameters

ParameterType
options?Readonly<{ abortSignal?: AbortSignal; }>

Returns

Promise<TResponse>

On this page