//! Generate events asynchronously for you application. /// An event subscription. pub struct Subscription { connections: Vec>>, } impl Subscription { pub fn none() -> Self { Self { connections: Vec::new(), } } pub fn batch( subscriptions: impl Iterator>, ) -> Self { Self { connections: subscriptions .flat_map(|subscription| subscription.connections) .collect(), } } pub fn connections( self, ) -> Vec>> { self.connections } } impl From for Subscription where T: Connection + 'static, { fn from(handle: T) -> Self { Self { connections: vec![Box::new(handle)], } } } /// The connection of an event subscription. pub trait Connection { type Input; type Output; fn id(&self) -> u64; fn stream( &self, input: Self::Input, ) -> futures::stream::BoxStream<'static, Self::Output>; } impl std::fmt::Debug for Subscription { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Subscription").finish() } }