use std::thread;
use std::time::Duration;
use crate::sleep::Sleeper;
#[cfg(feature = "tokio")]
use crate::sleep::{
AsyncSleepFuture,
AsyncSleeper,
};
#[derive(Clone, Copy, Debug, Default)]
pub struct SystemSleeper;
impl SystemSleeper {
#[inline]
pub const fn new() -> Self {
Self
}
}
impl Sleeper for SystemSleeper {
fn sleep_for(&self, duration: Duration) {
thread::sleep(duration);
}
}
#[cfg(feature = "tokio")]
impl AsyncSleeper for SystemSleeper {
fn sleep_for_async<'a>(&'a self, duration: Duration) -> AsyncSleepFuture<'a> {
Box::pin(tokio::time::sleep(duration))
}
}