use std::sync::Arc;
use crate::{
EventBusResult,
EventEnvelope,
};
type HandlerFn<T> = dyn Fn(EventEnvelope<T>) -> EventBusResult<()> + Send + Sync + 'static;
pub struct SubscriberInterceptorChain<T: Clone + Send + Sync + 'static> {
next: Arc<HandlerFn<T>>,
}
pub struct SubscriberInterceptorAnyChain {
next: Arc<dyn Fn() -> EventBusResult<()> + Send + Sync + 'static>,
}
impl SubscriberInterceptorAnyChain {
pub(crate) fn new(next: Arc<dyn Fn() -> EventBusResult<()> + Send + Sync + 'static>) -> Self {
Self { next }
}
pub fn proceed(&self) -> EventBusResult<()> {
(self.next)()
}
}
impl<T> SubscriberInterceptorChain<T>
where
T: Clone + Send + Sync + 'static,
{
pub(crate) fn new(
next: Arc<dyn Fn(EventEnvelope<T>) -> EventBusResult<()> + Send + Sync + 'static>,
) -> Self {
Self { next }
}
pub fn proceed(&self, envelope: EventEnvelope<T>) -> EventBusResult<()> {
(self.next)(envelope)
}
}