File tree Expand file tree Collapse file tree 8 files changed +14
-177
lines changed
Expand file tree Collapse file tree 8 files changed +14
-177
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,15 @@ use async_std::io;
88use async_std:: task;
99
1010fn main ( ) -> io:: Result < ( ) > {
11+ // This async scope times out after 5 seconds.
1112 task:: block_on ( io:: timeout ( Duration :: from_secs ( 5 ) , async {
1213 let stdin = io:: stdin ( ) ;
1314
15+ // Read a line from the standard input and display it.
1416 let mut line = String :: new ( ) ;
1517 stdin. read_line ( & mut line) . await ?;
18+ dbg ! ( line) ;
1619
17- print ! ( "Got line: {}" , line) ;
1820 Ok ( ( ) )
1921 } ) )
2022}
Original file line number Diff line number Diff line change 88/// use std::time::Duration;
99///
1010/// use async_std::future::pending;
11- /// use async_std::prelude::* ;
11+ /// use async_std::io ;
1212///
1313/// let dur = Duration::from_secs(1);
14- /// assert!(pending::<()>().timeout(dur).await.is_err());
14+ /// let fut = pending();
15+ ///
16+ /// let res: io::Result<()> = io::timeout(dur, fut).await;
17+ /// assert!(res.is_err());
1518/// #
1619/// # }) }
1720/// ```
Original file line number Diff line number Diff line change 1010/// # #![feature(async_await)]
1111/// # fn main() { async_std::task::block_on(async {
1212/// #
13- /// use async_std::future::ready ;
13+ /// use async_std::future;
1414///
15- /// assert_eq!(ready(10).await, 10);
15+ /// assert_eq!(future:: ready(10).await, 10);
1616/// #
1717/// # }) }
1818/// ```
Original file line number Diff line number Diff line change @@ -75,6 +75,5 @@ pub mod prelude;
7575pub mod stream;
7676pub mod sync;
7777pub mod task;
78- pub mod time;
7978
8079pub ( crate ) mod utils;
Original file line number Diff line number Diff line change 11//! The async prelude.
22//!
3- //! The prelude re-exports the most commonly used traits in async programming.
4- //!
5- //! # Examples
6- //!
7- //! Import the prelude to use the [`timeout`] combinator:
8- //!
9- //! ```no_run
10- //! # #![feature(async_await)]
11- //! # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
12- //! #
13- //! use std::time::Duration;
14- //!
15- //! use async_std::io;
16- //! use async_std::prelude::*;
17- //!
18- //! let stdin = io::stdin();
19- //! let mut line = String::new();
20- //! let dur = Duration::from_secs(5);
21- //!
22- //! stdin.read_line(&mut line).timeout(dur).await??;
23- //! #
24- //! # Ok(()) }) }
25- //! ```
26- //!
27- //! [`timeout`]: ../time/trait.Timeout.html#method.timeout
3+ //! The prelude re-exports the most commonly used traits in this crate.
284
295#[ doc( no_inline) ]
306pub use crate :: future:: Future ;
@@ -40,5 +16,3 @@ pub use crate::io::Write as _;
4016pub use crate :: stream:: Stream ;
4117#[ doc( no_inline) ]
4218pub use crate :: task_local;
43- #[ doc( no_inline) ]
44- pub use crate :: time:: Timeout as _;
Original file line number Diff line number Diff line change 11use std:: time:: Duration ;
22
3- use futures:: future;
4-
5- use crate :: time:: Timeout ;
3+ use crate :: future;
4+ use crate :: io;
65
76/// Sleeps for the specified amount of time.
87///
@@ -27,5 +26,5 @@ use crate::time::Timeout;
2726/// # }) }
2827/// ```
2928pub async fn sleep ( dur : Duration ) {
30- let _ = future :: pending :: < ( ) > ( ) . timeout ( dur) . await ;
29+ let _: io :: Result < ( ) > = io :: timeout ( dur, future :: pending ( ) ) . await ;
3130}
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments