You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
async-std/examples/stdin-timeout.rs

22 lines
478 B
Rust

5 years ago
//! Reads a line from stdin, or exits with an error if nothing is read in 5 seconds.
#![feature(async_await)]
use std::time::Duration;
5 years ago
use async_std::io;
use async_std::prelude::*;
use async_std::task;
5 years ago
fn main() -> io::Result<()> {
5 years ago
task::block_on(io::timeout(Duration::from_secs(5), async {
5 years ago
let stdin = io::stdin();
5 years ago
let mut line = String::new();
stdin.read_line(&mut line).await?;
5 years ago
5 years ago
print!("Got line: {}", line);
5 years ago
Ok(())
5 years ago
}))
5 years ago
}