Skip to content

About

Waiting on a child process with a timeout in Rust

Resources

Stars

78 stars

Watchers

3 watching

Forks

Latest commit

 

History

88 Commits

Folders and files

Repository files navigation

wait-timeout

Build Status

Documentation

Rust crate for waiting on a Child process with a timeout specified.

$ cargo add wait-timeout

Example:

use std::io;
use std::process::Command;
use std::time::{Duration, Instant};
use wait_timeout::ChildExt;

fn main() -> io::Result<()> {
    let mut child = Command::new("sleep").arg("100").spawn()?;

    let start = Instant::now();
    assert!(child.wait_timeout(Duration::from_millis(100))?.is_none());
    assert!(start.elapsed() > Duration::from_millis(100));

    child.kill()?;

    let start = Instant::now();
    assert!(child.wait_timeout(Duration::from_millis(100))?.is_some());
    assert!(start.elapsed() < Duration::from_millis(100));

    Ok(())
}

About

Waiting on a child process with a timeout in Rust

Resources

Stars

78 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages