2019-08-08 12:44:48 +00:00
|
|
|
//! Reads a line from stdin, or exits with an error if nothing is read in 5 seconds.
|
|
|
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
2019-08-14 01:47:39 +00:00
|
|
|
use async_std::io;
|
|
|
|
use async_std::task;
|
2019-08-08 12:44:48 +00:00
|
|
|
|
|
|
|
fn main() -> io::Result<()> {
|
2019-08-15 17:26:10 +00:00
|
|
|
// This async scope times out after 5 seconds.
|
2019-08-15 15:59:48 +00:00
|
|
|
task::block_on(io::timeout(Duration::from_secs(5), async {
|
2020-03-12 09:34:09 +00:00
|
|
|
let stdin = io::stdin();
|
2019-08-08 12:44:48 +00:00
|
|
|
|
2019-08-15 17:26:10 +00:00
|
|
|
// Read a line from the standard input and display it.
|
2019-08-15 15:59:48 +00:00
|
|
|
let mut line = String::new();
|
2020-03-12 09:34:09 +00:00
|
|
|
stdin.read_line(&mut line).await?;
|
2019-08-15 17:26:10 +00:00
|
|
|
dbg!(line);
|
2019-08-08 12:44:48 +00:00
|
|
|
|
|
|
|
Ok(())
|
2019-08-15 15:59:48 +00:00
|
|
|
}))
|
2019-08-08 12:44:48 +00:00
|
|
|
}
|