Struct gloo_timers::callback::Timeout
source · pub struct Timeout { /* private fields */ }
Expand description
Implementations§
source§impl Timeout
impl Timeout
sourcepub fn new<F>(millis: u32, callback: F) -> Timeoutwhere
F: 'static + FnOnce(),
pub fn new<F>(millis: u32, callback: F) -> Timeoutwhere F: 'static + FnOnce(),
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...
});
sourcepub fn forget(self) -> JsValue
pub fn forget(self) -> JsValue
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();
sourcepub fn cancel(self) -> Closure<dyn FnMut()>
pub fn cancel(self) -> Closure<dyn FnMut()>
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§
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more