Function darkfi::system::timeout::io_timeout

source ·
pub async fn io_timeout<F, T>(dur: Duration, f: F) -> Result<T>
where F: Future<Output = Result<T>>,
Expand description

Awaits an I/O future or times out after a duration of time.

If you want to await a non I/O future consider using timeout() instead.

§Examples

use std::time::Duration;
use std::io;

io_timeout(Duration::from_secs(5), async {
    let stdin = io::stdin();
    let mut line = String::new();
    let n = stdin.read_line(&mut line)?;
    Ok(())
})
.await?;