use std::future::Future;
use std::pin::Pin;
use std::time::{Duration, Instant, SystemTime};
pub trait Clock: Send + Sync {
fn now(&self) -> Instant;
fn wall_time(&self) -> SystemTime;
fn sleep(&self, duration: Duration) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>;
}
#[derive(Clone, Copy, Debug, Default)]
pub struct SystemClock;
impl Clock for SystemClock {
fn now(&self) -> Instant {
Instant::now()
}
fn wall_time(&self) -> SystemTime {
SystemTime::now()
}
fn sleep(&self, duration: Duration) -> Pin<Box<dyn Future<Output = ()> + Send + '_>> {
Box::pin(tokio::time::sleep(duration))
}
}