pub mod interval;
pub mod sleep;
pub mod wheel;
pub use interval::{interval, Interval};
pub use sleep::{sleep, sleep_until, Sleep};
pub(crate) use wheel::{TimerId, TimerWheel};
use std::cell::RefCell;
use std::time::Instant;
thread_local! {
static TIMER_WHEEL: RefCell<TimerWheel> =
RefCell::new(TimerWheel::new(Instant::now()));
}
pub(crate) fn with_timer_wheel<F, R>(f: F) -> R
where
F: FnOnce(&mut TimerWheel) -> R,
{
TIMER_WHEEL.with(|cell| f(&mut cell.borrow_mut()))
}
pub(crate) fn tick_timer_wheel(now: Instant) -> Vec<std::task::Waker> {
with_timer_wheel(|w| w.tick(now))
}
pub(crate) fn next_timer_deadline() -> Option<Instant> {
with_timer_wheel(|w| w.next_deadline())
}