File tree Expand file tree Collapse file tree 3 files changed +23
-24
lines changed Expand file tree Collapse file tree 3 files changed +23
-24
lines changed Original file line number Diff line number Diff 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 > {
Original file line number Diff line number Diff line change @@ -6,28 +6,6 @@ use futures_timer::Delay;
66use crate :: future:: Future ;
77use 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 ) ]
3311pub struct DelayFuture < F > {
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ pub use async_macros::{select, try_select};
5151use cfg_if:: cfg_if;
5252
5353pub use future:: Future ;
54+ pub use future:: FutureExt ;
5455pub use pending:: pending;
5556pub use poll_fn:: poll_fn;
5657pub use ready:: ready;
@@ -65,9 +66,7 @@ mod timeout;
6566cfg_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}
You can’t perform that action at this time.
0 commit comments