Skip to main content

spawn_firehose

Function spawn_firehose 

Source
pub async fn spawn_firehose<S>(
    config: &FirehoseConfig,
    state: S,
    handler: FirehoseHandler<S>,
) -> Result<JoinHandle<()>>
where S: Clone + Send + Sync + 'static,
Expand description

Spawn the firehose consumer as a pair of background tasks.

Returns a join handle for the reader task. The consumer architecture:

  1. Reader task — connects to the relay WebSocket, decodes incoming binary CBOR frames into FirehoseEvents, and sends them into a bounded mpsc channel. Reconnects with exponential backoff on error.
  2. 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.