|
1 | 1 | //! Setup for the tracker statistics.
|
2 | 2 | //!
|
3 | 3 | //! The [`factory`] function builds the structs needed for handling the tracker metrics.
|
4 |
| -use tokio::sync::broadcast; |
5 |
| - |
6 |
| -use crate::event::sender::ChannelSender; |
| 4 | +use crate::event::sender::Broadcaster; |
7 | 5 | use crate::{event, statistics};
|
8 | 6 |
|
9 |
| -const CHANNEL_CAPACITY: usize = 1024; |
10 |
| - |
11 | 7 | /// It builds the structs needed for handling the tracker metrics.
|
12 | 8 | ///
|
13 | 9 | /// It returns:
|
14 | 10 | ///
|
15 |
| -/// - An statistics event [`Sender`](crate::statistics::event::sender::Sender) that allows you to send events related to statistics. |
16 |
| -/// - An statistics [`Repository`](crate::statistics::repository::Repository) which is an in-memory repository for the tracker metrics. |
| 11 | +/// - An event [`Sender`](crate::event::sender::Sender) that allows you to send |
| 12 | +/// events related to statistics. |
| 13 | +/// - An statistics [`Repository`](crate::statistics::repository::Repository) |
| 14 | +/// which is an in-memory repository for the tracker metrics. |
17 | 15 | ///
|
18 |
| -/// When the input argument `tracker_usage_statistics`is false the setup does not run the event listeners, consequently the statistics |
19 |
| -/// events are sent are received but not dispatched to the handler. |
| 16 | +/// When the input argument `tracker_usage_statistics`is false the setup does |
| 17 | +/// not run the event listeners, consequently the statistics events are sent are |
| 18 | +/// received but not dispatched to the handler. |
20 | 19 | #[must_use]
|
21 | 20 | pub fn factory(tracker_usage_statistics: bool) -> (Option<Box<dyn event::sender::Sender>>, statistics::repository::Repository) {
|
22 |
| - let mut stats_event_sender: Option<Box<dyn event::sender::Sender>> = None; |
23 |
| - |
24 | 21 | let mut keeper = statistics::keeper::Keeper::new();
|
25 | 22 |
|
26 |
| - if tracker_usage_statistics { |
27 |
| - let (sender, _) = broadcast::channel(CHANNEL_CAPACITY); |
| 23 | + let opt_event_sender: Option<Box<dyn event::sender::Sender>> = if tracker_usage_statistics { |
| 24 | + let broadcaster = Broadcaster::default(); |
28 | 25 |
|
29 |
| - let receiver = sender.subscribe(); |
| 26 | + keeper.run_event_listener(broadcaster.subscribe()); |
30 | 27 |
|
31 |
| - stats_event_sender = Some(Box::new(ChannelSender { sender })); |
32 |
| - |
33 |
| - keeper.run_event_listener(receiver); |
34 |
| - } |
| 28 | + Some(Box::new(broadcaster)) |
| 29 | + } else { |
| 30 | + None |
| 31 | + }; |
35 | 32 |
|
36 |
| - (stats_event_sender, keeper.repository) |
| 33 | + (opt_event_sender, keeper.repository) |
37 | 34 | }
|
38 | 35 |
|
39 | 36 | #[cfg(test)]
|
|
0 commit comments