core/rustybot/src/ticker.rs
Giulio De Pasquale f211b2cded other stuff
2021-01-04 10:45:54 +00:00

32 lines
599 B
Rust

use tokio::time::{Duration, Instant};
pub struct Ticker {
duration: Duration,
start_time: Instant,
current_tick: u64,
}
impl Ticker {
pub fn new(duration: Duration) -> Self {
Ticker {
duration,
start_time: Instant::now(),
current_tick: 1,
}
}
pub fn inc(&mut self) {
self.current_tick += 1
}
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
}
}