[][src]Struct gloo_timers::callback::Timeout

#[must_use = "timeouts cancel on drop; either call `forget` or `drop` explicitly"]
pub struct Timeout { /* fields omitted */ }

A scheduled timeout.

See Timeout::new for scheduling new timeouts.

Once scheduled, you can either cancel so that it doesn't run or forget it so that it is un-cancel-able.

Methods

impl Timeout[src]

pub fn new<F>(millis: u32, callback: F) -> Timeout where
    F: 'static + FnOnce(), 
[src]

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...
});

pub fn forget(self) -> i32[src]

Make this timeout uncancel-able.

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();

pub fn cancel(self) -> Closure<dyn FnMut()>[src]

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

impl Debug for Timeout[src]

impl Drop for Timeout[src]

Auto Trait Implementations

impl !RefUnwindSafe for Timeout

impl !Send for Timeout

impl !Sync for Timeout

impl Unpin for Timeout

impl !UnwindSafe for Timeout

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.