ruva_core/bus_components/handler/
event.rs

1use crate::{bus_components::contexts::AtomicContextManager, prelude::TEvent};
2
3use std::pin::Pin;
4
5pub type Future<E> = Pin<Box<dyn futures::Future<Output = Result<(), E>> + Send>>;
6pub type FutureResult<E> = Result<Future<E>, E>;
7
8pub type Handlers<E> = Vec<Box<dyn Fn(std::sync::Arc<dyn TEvent>, AtomicContextManager) -> Future<E> + Send + Sync>>;
9
10pub enum EventHandlers<E> {
11	Sync(Handlers<E>),
12	Async(Handlers<E>),
13}
14impl<E> EventHandlers<E> {
15	pub fn extend(&mut self, handlers: Handlers<E>) {
16		match self {
17			Self::Sync(h) => h.extend(handlers),
18			Self::Async(h) => h.extend(handlers),
19		}
20	}
21}