pub struct Timeout { /* private fields */ }
Expand description
See more information about reset
and stop
methods
Implementations§
Source§impl Timeout
impl Timeout
Sourcepub async fn set(
timeout: Duration,
f: impl Future<Output = ()> + Send + 'static,
) -> Self
pub async fn set( timeout: Duration, f: impl Future<Output = ()> + Send + 'static, ) -> Self
Schedule the task inside closure after timeout
Sourcepub async fn reset(&self, timeout: Duration)
pub async fn reset(&self, timeout: Duration)
Reset timeout with a new value, i.e. to delay execution of your task
§Example
use std::time::Duration;
use async_timeouts::Timeout;
use tokio::sync::Notify;
use std::sync::Arc;
#[tokio::main]
async fn main() {
let event = Arc::new(Notify::new());
let event_cloned = event.clone();
let x = Timeout::set(Duration::from_secs(3), async move {
println!("This message will be printed after 6 seconds");
event_cloned.notify_one();
}).await;
x.reset(Duration::from_secs(6)).await;
event.notified().await;
}
Sourcepub async fn stop(&self)
pub async fn stop(&self)
Stop timer before your task will be executed
§Example
use std::time::Duration;
use async_timeouts::Timeout;
use tokio::sync::Notify;
use std::sync::Arc;
#[tokio::main]
async fn main() {
let event = Arc::new(Notify::new());
let event_cloned = event.clone();
let x = Timeout::set(Duration::from_secs(3), async move {
println!("This message will never be printed and event will never be notified.");
event_cloned.notify_one();
}).await;
x.stop().await;
event.notified().await;
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Timeout
impl RefUnwindSafe for Timeout
impl Send for Timeout
impl Sync for Timeout
impl Unpin for Timeout
impl UnwindSafe for Timeout
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