pub struct Timeout { /* private fields */ }
Expand description

A scheduled timeout.

See Timeout::new for scheduling new timeouts.

Once scheduled, you can drop the Timeout to clear it or forget to leak it. Once forgotten, the interval will keep running forever. This pattern is known as Resource Acquisition Is Initialization (RAII).

Implementations§

Schedule a timeout to invoke callback in millis milliseconds from now.

Example
use gloo_timers::callback::Timeout;

let timeout = Timeout::new(1_000, move || {
    // Do something...
});

Forgets this resource without clearing the timeout.

Returns the identifier returned by the original setTimeout call, and therefore you can still cancel the timeout by calling clearTimeout directly (perhaps via web_sys::clear_timeout_with_handle).

Example
use gloo_timers::callback::Timeout;

// We definitely want to do stuff, and aren't going to ever cancel this
// timeout.
Timeout::new(1_000, || {
    // Do stuff...
}).forget();

Cancel this timeout so that the callback is not invoked after the time is up.

The scheduled callback is returned.

Example
use gloo_timers::callback::Timeout;

let timeout = Timeout::new(1_000, || {
    // Do stuff...
});

// If actually we didn't want to set a timer, then cancel it.
if nevermind() {
    timeout.cancel();
}

Trait Implementations§

Formats the value using the given formatter. Read more

Disposes of the timeout, dually cancelling this timeout by calling clearTimeout directly.

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.