diff --git a/src/globals.rs b/src/globals.rs index 1187bc2..fda6936 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -3,6 +3,7 @@ use crate::store::Store; use hyper::server::conn::Http; use lazy_static::lazy_static; use std::sync::OnceLock; +use tokio::sync::broadcast::Sender; use tokio::sync::RwLock; pub struct Globals { @@ -10,6 +11,12 @@ pub struct Globals { pub store: OnceLock, pub http_server: Http, pub rid: OnceLock, + + /// This is a broadcast channel where new incoming events are advertised by their offset. + /// Every handler needs to listen to it and check if the incoming event matches any + /// subscribed fitlers for their client, and if so, send the event to their client under + /// that subscription. + pub new_events: Sender, } lazy_static! { @@ -18,11 +25,14 @@ lazy_static! { http_server.http1_only(true); http_server.http1_keep_alive(true); + let (sender, _) = tokio::sync::broadcast::channel(512); + Globals { config: RwLock::new(FriendlyConfig::default().into_config().unwrap()), store: OnceLock::new(), http_server, rid: OnceLock::new(), + new_events: sender, } }; }