Move delay method to FutureExt::delay

pull/349/head
k-nasa 5 years ago
parent 054f4fac74
commit b251fc999a

@ -105,6 +105,28 @@ extension_trait! {
}
pub trait FutureExt: std::future::Future {
/// Creates a future that is delayed before it starts yielding items.
///
/// # Examples
///
/// ```
/// # async_std::task::block_on(async {
/// use async_std::future;
/// use std::time::Duration;
/// use async_std::future::FutureExt;
///
/// let a = future::ready(1).delay(Duration::from_millis(2000));
/// dbg!(a.await);
/// # })
/// ```
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[cfg(any(feature = "unstable", feature = "docs"))]
fn delay(self, dur: Duration) -> DelayFuture<Self>
where
Self: Future + Sized
{
DelayFuture::new(self, dur)
}
}
impl<F: Future + Unpin + ?Sized> Future for Box<F> {

@ -6,28 +6,6 @@ use futures_timer::Delay;
use crate::future::Future;
use crate::task::{Context, Poll};
/// Creates a future that is delayed before it starts yielding items.
///
/// # Examples
///
/// ```
/// # async_std::task::block_on(async {
/// use async_std::future;
/// use std::time::Duration;
/// let a = future::delay(future::ready(1) ,Duration::from_millis(2000));
/// dbg!(a.await);
/// # })
/// ```
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[cfg(any(feature = "unstable", feature = "docs"))]
pub fn delay<F>(f: F, dur: Duration) -> DelayFuture<F>
where
F: Future,
{
DelayFuture::new(f, dur)
}
#[doc(hidden)]
#[derive(Debug)]
pub struct DelayFuture<F> {

@ -51,6 +51,7 @@ pub use async_macros::{select, try_select};
use cfg_if::cfg_if;
pub use future::Future;
pub use future::FutureExt;
pub use pending::pending;
pub use poll_fn::poll_fn;
pub use ready::ready;
@ -65,9 +66,7 @@ mod timeout;
cfg_if! {
if #[cfg(any(feature = "unstable", feature = "docs"))] {
mod into_future;
mod delay;
pub use into_future::IntoFuture;
pub use delay::delay;
}
}

Loading…
Cancel
Save