Skip to content
Snippets Groups Projects
governor.rs 374 B
Newer Older
Finn Bear's avatar
Finn Bear committed
/// Good for rate-limiting certain things.
Finn Bear's avatar
Finn Bear committed
#[derive(Default)]
pub struct Governor {
    last: f64,
}

impl Governor {
Finn Bear's avatar
Finn Bear committed
    /// Is the rate limit ready to allow another action?
Finn Bear's avatar
Finn Bear committed
    pub fn ready(&mut self, time: f64, limit: f64) -> bool {
        if time > self.last + limit {
            self.last = time;
            true
        } else {
            false
        }
    }
}