Skip to content

Commit b251fc9

Browse files
committed
Move delay method to FutureExt::delay
1 parent 054f4fa commit b251fc9

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

src/future/future.rs

+22
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ extension_trait! {
105105
}
106106

107107
pub trait FutureExt: std::future::Future {
108+
/// Creates a future that is delayed before it starts yielding items.
109+
///
110+
/// # Examples
111+
///
112+
/// ```
113+
/// # async_std::task::block_on(async {
114+
/// use async_std::future;
115+
/// use std::time::Duration;
116+
/// use async_std::future::FutureExt;
117+
///
118+
/// let a = future::ready(1).delay(Duration::from_millis(2000));
119+
/// dbg!(a.await);
120+
/// # })
121+
/// ```
122+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
123+
#[cfg(any(feature = "unstable", feature = "docs"))]
124+
fn delay(self, dur: Duration) -> DelayFuture<Self>
125+
where
126+
Self: Future + Sized
127+
{
128+
DelayFuture::new(self, dur)
129+
}
108130
}
109131

110132
impl<F: Future + Unpin + ?Sized> Future for Box<F> {

src/future/delay.rs renamed to src/future/future/delay.rs

-22
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,6 @@ use futures_timer::Delay;
66
use crate::future::Future;
77
use crate::task::{Context, Poll};
88

9-
/// Creates a future that is delayed before it starts yielding items.
10-
///
11-
/// # Examples
12-
///
13-
/// ```
14-
/// # async_std::task::block_on(async {
15-
/// use async_std::future;
16-
/// use std::time::Duration;
17-
18-
/// let a = future::delay(future::ready(1) ,Duration::from_millis(2000));
19-
/// dbg!(a.await);
20-
/// # })
21-
/// ```
22-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
23-
#[cfg(any(feature = "unstable", feature = "docs"))]
24-
pub fn delay<F>(f: F, dur: Duration) -> DelayFuture<F>
25-
where
26-
F: Future,
27-
{
28-
DelayFuture::new(f, dur)
29-
}
30-
319
#[doc(hidden)]
3210
#[derive(Debug)]
3311
pub struct DelayFuture<F> {

src/future/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub use async_macros::{select, try_select};
5151
use cfg_if::cfg_if;
5252

5353
pub use future::Future;
54+
pub use future::FutureExt;
5455
pub use pending::pending;
5556
pub use poll_fn::poll_fn;
5657
pub use ready::ready;
@@ -65,9 +66,7 @@ mod timeout;
6566
cfg_if! {
6667
if #[cfg(any(feature = "unstable", feature = "docs"))] {
6768
mod into_future;
68-
mod delay;
6969

7070
pub use into_future::IntoFuture;
71-
pub use delay::delay;
7271
}
7372
}

0 commit comments

Comments
 (0)