use std::future::Future;
use std::sync::Arc;
use crate::core::types::Context;
use crate::core::types::Envelope;
use crate::core::types::HandlerError;
use crate::core::types::Outcome;
pub trait Subscription: Clone + Send + Sync + 'static {
fn set_streams(&mut self, streams: Vec<Arc<str>>);
}
pub trait Broker: Clone + Send + Sync + 'static {
type AckToken: Clone + Send + Sync + 'static;
type Subscription: Subscription;
type Error: std::error::Error + Send + Sync + 'static;
fn poll(
&self, subscription: &Self::Subscription,
) -> impl Future<Output = Result<Vec<(Envelope, Self::AckToken)>, Self::Error>> + Send;
fn ack(&self, token: Self::AckToken) -> impl Future<Output = Result<(), Self::Error>> + Send;
fn reclaim(
&self, subscription: &Self::Subscription,
) -> impl Future<Output = Result<Vec<(Envelope, Self::AckToken)>, Self::Error>> + Send;
fn dead_letter(&self, envelope: &Envelope, reason: &str) -> impl Future<Output = Result<(), Self::Error>> + Send;
}
pub trait Handler<B: Broker>: Send + Sync + 'static {
const STREAMS: &'static [&'static str];
const MAX_IN_FLIGHT: usize = 16;
fn handle(
&self, ctx: &Context<B>, message: &Envelope,
) -> impl Future<Output = Result<Outcome, HandlerError>> + Send;
}