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;
|
use async_std::task;
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
task::block_on(async {
|
task::block_on(io::timeout(Duration::from_secs(5), async {
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
|
|
||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
|
stdin.read_line(&mut line).await?;
|
||||||
|
|
||||||
match stdin
|
print!("Got line: {}", line);
|
||||||
.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 :)"),
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,12 @@ use crate::task::{Context, Poll};
|
||||||
///
|
///
|
||||||
/// use async_std::io;
|
/// use async_std::io;
|
||||||
///
|
///
|
||||||
/// let stdin = io::stdin();
|
/// io::timeout(Duration::from_secs(5), async {
|
||||||
/// let mut line = String::new();
|
/// let stdin = io::stdin();
|
||||||
///
|
/// let mut line = String::new();
|
||||||
/// let dur = Duration::from_secs(5);
|
/// let n = stdin.read_line(&mut line).await?;
|
||||||
/// let n = io::timeout(dur, stdin.read_line(&mut line)).await?;
|
/// })
|
||||||
|
/// .await?;
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -61,7 +62,7 @@ where
|
||||||
Poll::Pending => match self.delay().poll(cx) {
|
Poll::Pending => match self.delay().poll(cx) {
|
||||||
Poll::Ready(_) => Poll::Ready(Err(io::Error::new(
|
Poll::Ready(_) => Poll::Ready(Err(io::Error::new(
|
||||||
io::ErrorKind::TimedOut,
|
io::ErrorKind::TimedOut,
|
||||||
"future has timed out",
|
"I/O operation has timed out",
|
||||||
))),
|
))),
|
||||||
Poll::Pending => Poll::Pending,
|
Poll::Pending => Poll::Pending,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue