2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-03-30 21:16:41 +00:00

Address comments

This commit is contained in:
Stjepan Glavina 2019-08-15 17:59:48 +02:00
parent d512e7c45c
commit e3fc67c1cb
2 changed files with 12 additions and 20 deletions

View file

@ -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(())
})
}))
}

View file

@ -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,
},