pub struct TimeWheel<T> { /* private fields */ }
Expand description
A binary-heap based timing wheel implementation.
Implementations§
Source§impl<T> TimeWheel<T>
impl<T> TimeWheel<T>
Sourcepub fn new(tick_interval: Duration) -> Self
pub fn new(tick_interval: Duration) -> Self
Create a time-wheel with minimum time interval resolution tick_interval
.
Sourcepub fn deadline(&mut self, deadline: Instant, value: T) -> Option<u64>
pub fn deadline(&mut self, deadline: Instant, value: T) -> Option<u64>
Create a new timer using provided deadline
.
Return None
if the deadline is already reach.
§Examples
use std::time::{ Duration, Instant };
use timing_wheel::TimeWheel;
use std::thread::sleep;
let mut time_wheel = TimeWheel::new(Duration::from_millis(1));
time_wheel.deadline(Instant::now() + Duration::from_millis(1), ());
sleep(Duration::from_millis(2));
let mut wakers = vec![];
time_wheel.spin(&mut wakers);
assert_eq!(wakers.into_iter().map(|v| v.1).collect::<Vec<_>>(), vec![()]);
Sourcepub fn after(&mut self, duration: Duration, value: T) -> Option<u64>
pub fn after(&mut self, duration: Duration, value: T) -> Option<u64>
Create a new deadline
with a value equal to Instant::now() + duration
.
§Examples
use std::time::Duration;
use timing_wheel::TimeWheel;
use std::thread::sleep;
let mut time_wheel = TimeWheel::new(Duration::from_millis(1));
time_wheel.after(Duration::from_millis(1), ());
sleep(Duration::from_millis(2));
let mut wakers = vec![];
time_wheel.spin(&mut wakers);
assert_eq!(wakers.into_iter().map(|v| v.1).collect::<Vec<_>>(), vec![()]);
Auto Trait Implementations§
impl<T> Freeze for TimeWheel<T>
impl<T> RefUnwindSafe for TimeWheel<T>where
T: RefUnwindSafe,
impl<T> Send for TimeWheel<T>where
T: Send,
impl<T> Sync for TimeWheel<T>where
T: Sync,
impl<T> Unpin for TimeWheel<T>where
T: Unpin,
impl<T> UnwindSafe for TimeWheel<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more