Struct gloo_timers::callback::Interval
source · pub struct Interval { /* private fields */ }
Expand description
Implementations§
source§impl Interval
impl Interval
sourcepub fn new<F>(millis: u32, callback: F) -> Intervalwhere
F: 'static + FnMut(),
pub fn new<F>(millis: u32, callback: F) -> Intervalwhere
F: 'static + FnMut(),
Schedule an interval to invoke callback
every millis
milliseconds.
Example
use gloo_timers::callback::Interval;
let interval = Interval::new(1_000, move || {
// Do something...
});
sourcepub fn forget(self) -> JsValue
pub fn forget(self) -> JsValue
Forget this resource without clearing the interval.
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();
sourcepub fn cancel(self) -> Closure<dyn FnMut()>
pub fn cancel(self) -> Closure<dyn FnMut()>
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();
}