context_async/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
mod timer;
mod context;
mod error;
mod with;

pub use timer::*;
pub use context::*;
pub use error::*;
pub use with::*;

pub use async_trait::async_trait;

pub struct TimeChecker(tokio::time::Instant);

impl Default for TimeChecker {
    fn default() -> Self {
        Self::new()
    }
}

impl TimeChecker {
    pub fn new() -> Self {
        Self(tokio::time::Instant::now())
    }

    pub fn not_exceed(&self, duration: tokio::time::Duration) -> bool {
        let diff = tokio::time::Instant::now() - self.0;

        diff < duration
    }
}