use std::sync::Arc;
use tokio::sync::broadcast;
use crate::core::types::{AccountType, ExchangeId, StreamEvent};
#[derive(Debug, Clone)]
pub struct FeedEvent {
pub exchange: ExchangeId,
pub account_type: AccountType,
pub symbol: String,
pub event: StreamEvent,
}
pub struct FeedHandle {
pub(crate) rx: broadcast::Receiver<FeedEvent>,
pub(crate) _keep_alive: Arc<()>,
}
impl FeedHandle {
pub async fn recv(&mut self) -> Option<FeedEvent> {
loop {
match self.rx.recv().await {
Ok(ev) => return Some(ev),
Err(broadcast::error::RecvError::Closed) => return None,
Err(broadcast::error::RecvError::Lagged(_)) => continue,
}
}
}
pub fn into_receiver(self) -> broadcast::Receiver<FeedEvent> { self.rx }
}