use crate::SerializedEnvelope;
use crate::failure::Classify;
pub trait Publisher: Send + Sync {
type Error: std::error::Error + Send + Sync + 'static + Classify;
fn publish(
&self,
envelope: &SerializedEnvelope,
) -> impl Future<Output = Result<(), Self::Error>> + Send;
fn publish_batch(
&self,
envelopes: &[SerializedEnvelope],
) -> impl Future<Output = Vec<Result<(), Self::Error>>> + Send {
async move {
let mut out = Vec::with_capacity(envelopes.len());
for envelope in envelopes {
out.push(self.publish(envelope).await);
}
out
}
}
}