2021-01-02 12:16:48 +00:00
|
|
|
use tokio::time::{Duration, Instant};
|
|
|
|
|
|
|
|
pub struct Ticker {
|
|
|
|
duration: Duration,
|
|
|
|
start_time: Instant,
|
|
|
|
current_tick: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ticker {
|
2021-01-04 10:45:54 +00:00
|
|
|
pub fn new(duration: Duration) -> Self {
|
2021-01-02 12:16:48 +00:00
|
|
|
Ticker {
|
|
|
|
duration,
|
|
|
|
start_time: Instant::now(),
|
|
|
|
current_tick: 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 10:45:54 +00:00
|
|
|
pub fn inc(&mut self) {
|
2021-01-02 12:16:48 +00:00
|
|
|
self.current_tick += 1
|
|
|
|
}
|
2021-01-04 10:45:54 +00:00
|
|
|
|
|
|
|
pub fn duration(&self) -> Duration {
|
|
|
|
self.duration
|
|
|
|
}
|
|
|
|
pub fn start_time(&self) -> Instant {
|
|
|
|
self.start_time
|
|
|
|
}
|
|
|
|
pub fn current_tick(&self) -> u64 {
|
|
|
|
self.current_tick
|
|
|
|
}
|
2021-01-02 12:16:48 +00:00
|
|
|
}
|