Relates to: - https://github.com/torrust/torrust-tracker/issues/1444 - https://github.com/torrust/torrust-tracker/issues/1395 The `Keeper` type is responsible for: - Task 1. Creating the event broadcast channel. - Task 2. Creating the sender. - Task 3. Creating the receivers. - Task 4. Run the event listener to update the stats. Since our goal is to [decouple events from stats](https://github.com/torrust/torrust-tracker/issues/1395), I will: - Remove Task 4 from the `Keeper`. - Extract a new package with shared code for events, excluding logic for statistics. I think we can also rename the keeper, the final code would be: ```rust use std::sync::Arc; use tokio::sync::broadcast::Receiver; use crate::event::sender::{self, Broadcaster}; use crate::event::Event; pub struct Keeper { pub enable_sender: bool, pub broadcaster: Broadcaster, } impl Default for Keeper { fn default() -> Self { let enable_sender = true; let broadcaster = Broadcaster::default(); Self::new(enable_sender, broadcaster) } } impl Keeper { #[must_use] pub fn new(enable_sender: bool, broadcaster: Broadcaster) -> Self { Self { enable_sender, broadcaster, } } #[must_use] pub fn sender(&self) -> Arc<Option<Box<dyn sender::Sender>>> { if self.enable_sender { Arc::new(Some(Box::new(self.broadcaster.clone()))) } else { Arc::new(None) } } #[must_use] pub fn receiver(&self) -> Receiver<Event> { self.broadcaster.subscribe() } } ``` I think a good name could be "EventBus". cc @da2ce7
Activity
refactor: [torrust#1478] decouple events from stats in http core keeper
refactor: [torrust#1478] decouple events from stats in udp core keeper
refactor: [torrust#1478] decouple events from stats in udp server keeper
refactor: [torrust#1478] inline keeper_factory fn
refactor: [torrust#1478] inline factory fn in http core stats
refactor: [torrust#1478] inline factory fn in udp core stats
refactor: [torrust#1478] inline factory fn in udp server stats
refactor: [torrust#1478] rename Keeper to EventBus
refactor: [torrust#1478] rename Keeper variables
refactor: [torrust#1478] rename struct fields for Keeper type
refactor: [torrust#1478] move EventBus to event mod
[-]Overhaul stats: Extract events package[/-][+]Overhaul stats: Extract events package (part 1)[/+]Merge #1479: Overhaul stats: Extract events package (part 1)