pub struct WheelTimer { /* private fields */ }
Expand description
A reference-counted handle to a time wheel-based timer.
§Examples
use wheeltimer::WheelTimer;
#[tokio::main]
async fn main() {
let timer = WheelTimer::new(tokio::time::Duration::from_millis(100), 1024, 100000).unwrap();
timer.start().await;
let timeout = timer.new_timeout(tokio::time::Duration::from_secs(2),
async move {
// async task logic here
println!("a delay task is executed");
}
).await;
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
timer.stop().await;
}
Implementations§
Source§impl WheelTimer
impl WheelTimer
pub fn new( tick_duration: Duration, ticks_per_wheel: u32, max_pending_timeouts: u64, ) -> Result<Self, Error>
pub async fn start(&self)
pub async fn stop(&self)
pub async fn new_timeout<F>( &self, delay: Duration, task: F, ) -> Result<Timeout, Error>
pub fn pending_timeouts(&self) -> u64
Trait Implementations§
Source§impl Clone for WheelTimer
impl Clone for WheelTimer
Source§fn clone(&self) -> WheelTimer
fn clone(&self) -> WheelTimer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for WheelTimer
impl !RefUnwindSafe for WheelTimer
impl Send for WheelTimer
impl Sync for WheelTimer
impl Unpin for WheelTimer
impl !UnwindSafe for WheelTimer
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