pub fn set_interval<T>(handler: T, timeout: i32) -> Result<i32, JsValue>where
T: Fn() + 'static,Expand description
Javascript setInterval() method
The setInterval() method, offered on the Window and Worker interfaces, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.
This method returns an interval ID which uniquely identifies the interval, so you can remove it later by calling javascript’s clearInterval() function or clear_interval function
§Arguments
-
handler- A Rust closure to be executed everytimeoutmilliseconds. The first execution happens aftertimeoutmilliseconds. -
timeout- The execution interval in milliseconds. 1000 milliseconds == 1 second
§Panics
This function will panic if you try to call this outside of the web such as node.js runtime
§Example
use std::cell::Cell;
use weblog::console_log;
use webru::set_interval;
let counter: Cell<usize> = Cell::new(0);
set_interval(
// This closure will execute after every 2 secends
move || {
console_log!("The counter: ", counter.get());
counter.set(counter.get() + 1);
},
2000,
)
.unwrap();