mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-23 08:46:46 +00:00
Move delay method to FutureExt::delay
This commit is contained in:
parent
054f4fac74
commit
b251fc999a
3 changed files with 23 additions and 24 deletions
|
@ -105,6 +105,28 @@ extension_trait! {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FutureExt: std::future::Future {
|
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> {
|
impl<F: Future + Unpin + ?Sized> Future for Box<F> {
|
||||||
|
|
|
@ -6,28 +6,6 @@ use futures_timer::Delay;
|
||||||
use crate::future::Future;
|
use crate::future::Future;
|
||||||
use crate::task::{Context, Poll};
|
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)]
|
#[doc(hidden)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DelayFuture<F> {
|
pub struct DelayFuture<F> {
|
|
@ -51,6 +51,7 @@ pub use async_macros::{select, try_select};
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
pub use future::Future;
|
pub use future::Future;
|
||||||
|
pub use future::FutureExt;
|
||||||
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;
|
||||||
|
@ -65,9 +66,7 @@ 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 delay;
|
|
||||||
|
|
||||||
pub use into_future::IntoFuture;
|
pub use into_future::IntoFuture;
|
||||||
pub use delay::delay;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue