pub async fn spawn_firehose<S>(
config: &FirehoseConfig,
state: S,
handler: FirehoseHandler<S>,
) -> Result<JoinHandle<()>>Expand description
Spawn the firehose consumer as a pair of background tasks.
Returns a join handle for the reader task. The consumer architecture:
- Reader task — connects to the relay WebSocket, decodes incoming
binary CBOR frames into
FirehoseEvents, and sends them into a boundedmpscchannel. Reconnects with exponential backoff on error. - Dispatcher task — reads events from the channel and invokes the user-supplied handler for each one.
Backpressure: when the channel is full, the reader drops events and
increments the events_dropped metric counter.
The state parameter is an arbitrary Clone + Send + 'static value
that is forwarded to the handler on every event. In a typical atrg app
this is AppState, but the consumer itself does not depend on
atrg-core to avoid a cyclic dependency.