cbsk_timer/timer/
mod.rs

1use std::time::Duration;
2
3pub(crate) mod timer_state;
4pub(crate) mod timer_run;
5pub mod simple_timer;
6pub(crate) mod once;
7
8/// timer tasks
9pub trait Timer: 'static {
10    /// timer name
11    fn name(&self) -> &str;
12
13    /// timer run logic
14    fn run(&self);
15
16    /// ren before, default return true<br />
17    /// please execute the non blocking logic that ends immediately<br />
18    /// do nothing when return false<br />
19    /// execute [Self::run] in the thread pool when return true
20    fn run_before(&self) -> bool { true }
21
22    /// the timer is ended<br />
23    /// default is false
24    fn ended(&self) -> bool { false }
25
26    /// task loop interval<br />
27    /// if return None, will run continuously
28    fn interval(&self) -> Option<Duration> {
29        None
30    }
31
32    /// start timer
33    fn start(self) where Self: Sized {
34        super::push_timer(self);
35        super::run();
36    }
37}