forked from mirror/async-std
Address comments
This commit is contained in:
parent
d512e7c45c
commit
e3fc67c1cb
2 changed files with 12 additions and 20 deletions
|
@ -9,22 +9,13 @@ use async_std::prelude::*;
|
|||
use async_std::task;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
task::block_on(async {
|
||||
task::block_on(io::timeout(Duration::from_secs(5), async {
|
||||
let stdin = io::stdin();
|
||||
|
||||
let mut line = String::new();
|
||||
stdin.read_line(&mut line).await?;
|
||||
|
||||
match stdin
|
||||
.read_line(&mut line)
|
||||
.timeout(Duration::from_secs(5))
|
||||
.await
|
||||
{
|
||||
Ok(res) => {
|
||||
res?;
|
||||
print!("Got line: {}", line);
|
||||
}
|
||||
Err(_) => println!("You have only 5 seconds to enter a line. Try again :)"),
|
||||
}
|
||||
|
||||
print!("Got line: {}", line);
|
||||
Ok(())
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -20,11 +20,12 @@ use crate::task::{Context, Poll};
|
|||
///
|
||||
/// use async_std::io;
|
||||
///
|
||||
/// let stdin = io::stdin();
|
||||
/// let mut line = String::new();
|
||||
///
|
||||
/// let dur = Duration::from_secs(5);
|
||||
/// let n = io::timeout(dur, stdin.read_line(&mut line)).await?;
|
||||
/// io::timeout(Duration::from_secs(5), async {
|
||||
/// let stdin = io::stdin();
|
||||
/// let mut line = String::new();
|
||||
/// let n = stdin.read_line(&mut line).await?;
|
||||
/// })
|
||||
/// .await?;
|
||||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
|
@ -61,7 +62,7 @@ where
|
|||
Poll::Pending => match self.delay().poll(cx) {
|
||||
Poll::Ready(_) => Poll::Ready(Err(io::Error::new(
|
||||
io::ErrorKind::TimedOut,
|
||||
"future has timed out",
|
||||
"I/O operation has timed out",
|
||||
))),
|
||||
Poll::Pending => Poll::Pending,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue