OXYGENHUB
◆ v0.4.1 oxygenhub / crates / hub / src / events.rs
772 B · Rust · last changed Milestone 0.5: API, webhooks, checks 1 month ago source blame history raw
1
//! In-process event bus: nudges the webhook worker and streams proposal
2
//! updates to open pages over server-sent events (hub spec §13.1).
3
4
use hub_api::ProposalEvent;
5
use tokio::sync::broadcast;
6
7
pub struct Events {
8
    pub deliveries: broadcast::Sender<()>,
9
    pub proposals: broadcast::Sender<(i64, ProposalEvent)>,
10
}
11
12
impl Default for Events {
13
    fn default() -> Self {
14
        Events { deliveries: broadcast::channel(16).0, proposals: broadcast::channel(256).0 }
15
    }
16
}
17
18
impl Events {
19
    pub fn notify_deliveries(&self) {
20
        let _ = self.deliveries.send(());
21
    }
22
23
    /// Announce something about a proposal of a repository.
24
    pub fn proposal(&self, repo_id: i64, event: ProposalEvent) {
25
        let _ = self.proposals.send((repo_id, event));
26
    }
27
}