saito_core/core/process/
process_event.rs

1use std::time::Duration;
2
3use crate::core::defs::Timestamp;
4use async_trait::async_trait;
5
6use crate::core::io::network_event::NetworkEvent;
7
8/// Event Processing trait for the controllers. Handles both events from actions and timer
9#[async_trait]
10pub trait ProcessEvent<T>
11where
12    T: Send,
13{
14    /// Processes an event coming from other peers via network controller
15    ///
16    /// # Arguments
17    ///
18    /// * `event`:
19    ///
20    /// returns: Option<()>
21    ///
22    /// # Examples
23    ///
24    /// ```
25    ///
26    /// ```
27    async fn process_network_event(&mut self, event: NetworkEvent) -> Option<()>;
28    /// Triggered with each timer tick. duration will vary due to other processing tasks in the same thread.
29    ///
30    /// # Arguments
31    ///
32    /// * `duration`:
33    ///
34    /// returns: Option<()>
35    ///
36    /// # Examples
37    ///
38    /// ```
39    ///
40    /// ```
41    async fn process_timer_event(&mut self, duration: Duration) -> Option<()>;
42    /// Processes the incoming events from other threads/controllers.
43    ///
44    /// # Arguments
45    ///
46    /// * `event`:
47    ///
48    /// returns: Option<()>
49    ///
50    /// # Examples
51    ///
52    /// ```
53    ///
54    /// ```
55    async fn process_event(&mut self, event: T) -> Option<()>;
56    async fn on_init(&mut self);
57
58    async fn on_stat_interval(&mut self, current_time: Timestamp);
59
60    fn is_ready_to_process(&self) -> bool;
61}