File tree 3 files changed +23
-24
lines changed
3 files changed +23
-24
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,28 @@ extension_trait! {
105
105
}
106
106
107
107
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
+ }
108
130
}
109
131
110
132
impl <F : Future + Unpin + ?Sized > Future for Box <F > {
Original file line number Diff line number Diff line change @@ -6,28 +6,6 @@ use futures_timer::Delay;
6
6
use crate :: future:: Future ;
7
7
use crate :: task:: { Context , Poll } ;
8
8
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
-
31
9
#[ doc( hidden) ]
32
10
#[ derive( Debug ) ]
33
11
pub struct DelayFuture < F > {
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ pub use async_macros::{select, try_select};
51
51
use cfg_if:: cfg_if;
52
52
53
53
pub use future:: Future ;
54
+ pub use future:: FutureExt ;
54
55
pub use pending:: pending;
55
56
pub use poll_fn:: poll_fn;
56
57
pub use ready:: ready;
@@ -65,9 +66,7 @@ mod timeout;
65
66
cfg_if ! {
66
67
if #[ cfg( any( feature = "unstable" , feature = "docs" ) ) ] {
67
68
mod into_future;
68
- mod delay;
69
69
70
70
pub use into_future:: IntoFuture ;
71
- pub use delay:: delay;
72
71
}
73
72
}
You can’t perform that action at this time.
0 commit comments