Struct gloo_timers::future::TimeoutFuture
source · [−]pub struct TimeoutFuture { /* private fields */ }Expand description
A scheduled timeout as a Future.
See TimeoutFuture::new for scheduling new timeouts.
Once scheduled, if you change your mind and don’t want the timeout to fire,
you can drop the future.
A timeout future will never resolve to Err. Its only failure mode is when
the timeout is so long that it is effectively infinite and never fires.
Example
use gloo_timers::future::TimeoutFuture;
use futures_util::future::{select, Either};
use wasm_bindgen_futures::spawn_local;
spawn_local(async {
match select(TimeoutFuture::new(1_000), TimeoutFuture::new(2_000)).await {
Either::Left((val, b)) => {
// Drop the `2_000` ms timeout to cancel its timeout.
drop(b);
}
Either::Right((a, val)) => {
panic!("the `1_000` ms timeout should have won this race");
}
}
});Implementations
pub fn new(millis: u32) -> TimeoutFutureⓘNotable traits for TimeoutFutureimpl Future for TimeoutFuture type Output = ();
pub fn new(millis: u32) -> TimeoutFutureⓘNotable traits for TimeoutFutureimpl Future for TimeoutFuture type Output = ();
Notable traits for TimeoutFuture
impl Future for TimeoutFuture type Output = ();Create a new timeout future.
Remember that futures do nothing unless polled or spawned, so either
pass this future to wasm_bindgen_futures::spawn_local or use it inside
another future.
Example
use gloo_timers::future::TimeoutFuture;
use wasm_bindgen_futures::spawn_local;
spawn_local(async {
TimeoutFuture::new(1_000).await;
// Do stuff after one second...
});Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for TimeoutFuture
impl !Send for TimeoutFuture
impl !Sync for TimeoutFuture
impl Unpin for TimeoutFuture
impl !UnwindSafe for TimeoutFuture
Blanket Implementations
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (
into_future)The output that the future will produce on completion.
type Future = F
type Future = F
🔬 This is a nightly-only experimental API. (
into_future)Which kind of future are we turning this into?
🔬 This is a nightly-only experimental API. (
into_future)Creates a future from a value.