mirror of
https://github.com/mikedilger/chorus.git
synced 2026-05-03 06:51:42 +00:00
Add a global channel for new event advertisement (stores event offsets)
This commit is contained in:
parent
7f1ddff6e4
commit
52b449b6c7
@ -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<Store>,
|
||||
pub http_server: Http,
|
||||
pub rid: OnceLock<String>,
|
||||
|
||||
/// 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<usize>,
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user