/** * Shared reconnect loop for WS subscriptions (oracle, slot, native SOL, * and AccountSubscriptionManager). * * Guarantees: * - Auto-reconnect with exponential backoff, capped at 30s. * - Backoff escalates ONLY after a connection that never delivered a * message — once any message arrives, the next reconnect restarts at * `baseDelay`. (A healthy connection that drops shouldn't wait 30s.) * - Consumer callback throws are isolated — reported via `onError` but * never tear down the WS. * - Clean stream close → reconnect after `baseDelay` (no escalation). * - Returned unsubscribe aborts the loop AND any pending sleep. */ import { type RpcSubscriptions, type SolanaRpcSubscriptionsApi } from '@solana/kit'; export declare const WS_RECONNECT_DELAY_MS = 500; export interface WsReconnectLoopParams { wsRpc: RpcSubscriptions; /** Called on initial connect and every reconnect. * * **REQUIRED contract:** the returned async iterable's underlying * subscription MUST honor `abortSignal`. `unsubscribe()` aborts the loop * via this signal; an implementation that ignores it will leave the loop * hung awaiting `subscribe()` and prevent teardown. * * `@solana/kit` subscription factories accept `{ abortSignal }` and honor * it natively — pass it through verbatim. */ subscribe: (wsRpc: RpcSubscriptions, abortSignal: AbortSignal) => Promise>; /** Throws are caught and routed to {@link onError}. */ onMessage: (message: TMessage) => void; /** Defaults to `console.error`. Throws here are swallowed (logged) so a * buggy onError can't tear down the loop. */ onError?: (error: unknown) => void; /** Lifecycle logging hook. Defaults to noop. */ onLog?: (...args: unknown[]) => void; /** Called before every reconnect (NOT initial connect). Use to refresh * state via HTTP after long downtime. * * **Best-effort.** A throw is routed to `onError` and reconnect proceeds * with cached state — wrap with internal retry if mandatory. */ onBeforeReconnect?: () => void | Promise; /** Fires after `subscribe()` resolves successfully — i.e. the handshake * completed, but the stream has NOT yet delivered any message. This is * the "subscribed" milestone, not "healthy / receiving data". For the * latter, gate on the first `onMessage` call. * * The reconnect loop deliberately treats subscribed and first-message * differently: only the first message resets the backoff counter. */ onSubscribed?: () => void; /** Initial reconnect delay; doubles per failure, capped at 30s. Default 500. */ reconnectDelayMs?: number; } export declare function runReconnectLoop(params: WsReconnectLoopParams): () => void; //# sourceMappingURL=wsReconnectLoop.d.ts.map