mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-24 01:06:46 +00:00
stabilize future::timeout (#335)
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
This commit is contained in:
parent
49faea2023
commit
00d936488b
2 changed files with 2 additions and 8 deletions
|
@ -54,18 +54,18 @@ pub use future::Future;
|
||||||
pub use pending::pending;
|
pub use pending::pending;
|
||||||
pub use poll_fn::poll_fn;
|
pub use poll_fn::poll_fn;
|
||||||
pub use ready::ready;
|
pub use ready::ready;
|
||||||
|
pub use timeout::{timeout, TimeoutError};
|
||||||
|
|
||||||
pub(crate) mod future;
|
pub(crate) mod future;
|
||||||
mod pending;
|
mod pending;
|
||||||
mod poll_fn;
|
mod poll_fn;
|
||||||
mod ready;
|
mod ready;
|
||||||
|
mod timeout;
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(any(feature = "unstable", feature = "docs"))] {
|
if #[cfg(any(feature = "unstable", feature = "docs"))] {
|
||||||
mod into_future;
|
mod into_future;
|
||||||
mod timeout;
|
|
||||||
|
|
||||||
pub use into_future::IntoFuture;
|
pub use into_future::IntoFuture;
|
||||||
pub use timeout::{timeout, TimeoutError};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,6 @@ use crate::task::{Context, Poll};
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
|
||||||
#[cfg(any(feature = "unstable", feature = "docs"))]
|
|
||||||
pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>
|
pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>
|
||||||
where
|
where
|
||||||
F: Future<Output = T>,
|
F: Future<Output = T>,
|
||||||
|
@ -42,8 +40,6 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A future that times out after a duration of time.
|
/// A future that times out after a duration of time.
|
||||||
#[doc(hidden)]
|
|
||||||
#[allow(missing_debug_implementations)]
|
|
||||||
struct TimeoutFuture<F> {
|
struct TimeoutFuture<F> {
|
||||||
future: F,
|
future: F,
|
||||||
delay: Delay,
|
delay: Delay,
|
||||||
|
@ -69,8 +65,6 @@ impl<F: Future> Future for TimeoutFuture<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error returned when a future times out.
|
/// An error returned when a future times out.
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
|
||||||
#[cfg(any(feature = "unstable", feature = "docs"))]
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub struct TimeoutError {
|
pub struct TimeoutError {
|
||||||
_private: (),
|
_private: (),
|
||||||
|
|
Loading…
Reference in a new issue