//! `BusReceiver`: subscriber handle returned by a SharingBus-like fan-out.
//!
//! This type lives in `dirigent_protocol` (rather than next to its only
//! producer in `dirigent_core::sharing::bus`) so that downstream consumers
//! such as `dirigent_archivist` can accept a `BusReceiver` without taking
//! on a dependency on `dirigent_core` — which would be a dependency cycle.
//!
//! It is intentionally a dumb data container: just `id`, `rx`, and the
//! `lagged` counter that the producer task increments when it has to drop
//! events for a slow subscriber. No logic lives here.

use std::sync::Arc;
use std::sync::atomic::AtomicU64;

use tokio::sync::mpsc;

use crate::streaming::BusEvent;

/// Receiver handle returned to subscribers by a SharingBus-style fan-out.
///
/// `lagged` counts how many events were dropped because the underlying
/// mpsc queue was full when the worker tried to deliver.
pub struct BusReceiver {
    pub id: u64,
    pub rx: mpsc::Receiver<BusEvent>,
    pub lagged: Arc<AtomicU64>,
}
