use crate::{error::BusError, event::Event};
use async_trait::async_trait;
#[derive(Debug, Clone)]
pub struct PubReceipt {
pub stream: String,
pub sequence: u64,
pub duplicate: bool,
pub buffered: bool,
}
#[async_trait]
pub trait Publisher: Send + Sync {
async fn publish<E: Event>(&self, event: &E) -> Result<PubReceipt, BusError>;
async fn publish_batch<E: Event>(&self, events: &[E]) -> Result<Vec<PubReceipt>, BusError> {
let mut receipts = Vec::with_capacity(events.len());
for event in events {
receipts.push(self.publish(event).await?);
}
Ok(receipts)
}
}