[][src]Struct gloo_timers::callback::Interval

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

A scheduled interval.

See Interval::new for scheduling new intervals.

Once scheduled, you can either cancel so that it ceases to fire or forget it so that it is un-cancel-able.

Methods

impl Interval[src]

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

Schedule an interval to invoke callback every millis milliseconds.

Example

use gloo_timers::callback::Interval;

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

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

Make this interval uncancel-able.

Returns the identifier returned by the original setInterval call, and therefore you can still cancel the interval by calling clearInterval directly (perhaps via web_sys::clear_interval_with_handle).

Example

use gloo_timers::callback::Interval;

// We want to do stuff every second, indefinitely.
Interval::new(1_000, || {
    // Do stuff...
}).forget();

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

Cancel this interval so that the callback is no longer periodically invoked.

The scheduled callback is returned.

Example

use gloo_timers::callback::Interval;

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

// If we don't want this interval to run anymore, then cancel it.
if nevermind() {
    interval.cancel();
}

Trait Implementations

impl Drop for Interval[src]

impl Debug for Interval[src]

Auto Trait Implementations

impl !Sync for Interval

impl !Send for Interval

impl Unpin for Interval

impl !UnwindSafe for Interval

impl !RefUnwindSafe for Interval

Blanket Implementations

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

impl<T> From<T> for 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.

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

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

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