Client Lifecycle
Creating a client
Notes:
build()returns a ready client handle. HTTP queries work immediately.- Live subscriptions additionally use the shared WebSocket.
base_urlis required; everything else has defaults.
WebSocket lazy connect (default: true)
ConnectionOptions::ws_lazy_connect defaults to true. The shared WebSocket opens on the first live() or live_events() call, not at build() time.
Eager connect:
Explicit connect and disconnect
Call connect() before multiple subscriptions so they share one socket and one auth context.
Auth refresh model
- Static
AuthProvideron the builder is resolved at build time. DynamicAuthProviderre-runs on connect/reconnect viafresh_auth().auth_refresherhandlesTOKEN_EXPIREDduring query/subscription operations.set_auth/update_shared_authpush new credentials without rebuilding the client.
See Authentication and Auth-Aware Client.
Event handlers
EventHandlers callbacks:
| Callback | When it fires |
|---|---|
on_connect | Shared WebSocket becomes ready |
on_disconnect | Connection closes (DisconnectReason) |
on_error | Connection or protocol errors (ConnectionError) |
on_receive / on_send | Optional debug hooks for wire messages |
Handlers are Arc-backed and safe to share across cloned clients.
Timeouts and retries
timeout— HTTP request timeout (default 30s)max_retries— retries for idempotent HTTP queries (default 3)timeouts(...)— finer-grained send/receive limits for HTTP and WebSocket
Shutdown checklist
live.close().await?/events.close().await?for each open subscriptionconsumer.close().await?for each topic consumerclient.disconnect().awaitto close the shared WebSocket
Long-running services should always close streams before dropping the client.
Cloning and sharing
KalamLinkClient is cloneable (Arc internally). Clone handles share connection state — useful for spawning multiple subscription tasks from one service.
Next
Last updated on