pub struct Timeout<F: Future> { /* private fields */ }Expand description
Wraps a future and cancels it if it does not complete within duration.
Created by timeout(). Returns Ok(value) if the future wins the race,
or Err(Elapsed) if the timer fires first.
§Implementation
Both the inner future and the deadline share the same Waker. Whichever
completes first causes poll to be called again, where the winner is
detected and returned.
ⓘ
ctx.spawn(async move {
match timeout(Duration::from_secs(5), fetch_data()).await {
Ok(data) => display(data),
Err(Elapsed) => show_error("Request timed out"),
}
});Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for Timeout<F>where
F: Freeze,
impl<F> RefUnwindSafe for Timeout<F>where
F: RefUnwindSafe,
impl<F> Send for Timeout<F>where
F: Send,
impl<F> Sync for Timeout<F>where
F: Sync,
impl<F> Unpin for Timeout<F>where
F: Unpin,
impl<F> UnsafeUnpin for Timeout<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for Timeout<F>where
F: UnwindSafe,
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more
Source§impl<T> MaybeBoxed<Box<T>> for T
impl<T> MaybeBoxed<Box<T>> for T
Source§fn maybe_boxed(self) -> Box<T>
fn maybe_boxed(self) -> Box<T>
Convert
Source§impl<T> MaybeBoxed<T> for T
impl<T> MaybeBoxed<T> for T
Source§fn maybe_boxed(self) -> T
fn maybe_boxed(self) -> T
Convert