pub struct Timeout<R: Runtime> { /* private fields */ }
Expand description

A shared timeout.

Example

use std::time::Duration;

let timeout_secs = Duration::from_secs(10);
// Use the tokio runtime
let runtime = async_shared_timeout::runtime::Tokio::new();
let timeout = async_shared_timeout::Timeout::new(runtime, timeout_secs);
tokio::select! {
    _ = timeout.wait() => {
        println!("timeout expired!");
    }
    _ = async {
        while let Some(cmd) = read_command().await {
            println!("command received: {:?}", cmd);
            timeout.reset();
        }
    } => {
        println!("no more commands!");
    }
}

Implementations§

Create a new timeout that expires after default_timeout

Panics

Panics if default_timeout is longer than ~584 years

Reset the timeout to the default time.

This function is cheap to call.

Panics

Panics if over ~584 years have elapsed since the timer started.

The default timeout. Timeout will be reset to this value upon a successful operation.

Change the default timeout.

Warning: if this timeout is shorter than previous one, it will only update after the previous timeout has expired!

Panics

Panics if default_timeout is longer than ~584 years

Wait for the timeout to expire

This is a function that’s expensive to start, so for best performance, only call it once per timer - launch it separately and call reset from the other futures (see the example in top-level documentation).

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.