alexcrichton/wait-timeout

Waiting on a child process with a timeout in Rust

Rust

77

88 commits

updated May 17, 2025

See the code

README

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(())
}

alexcrichton/wait-timeout

Waiting on a child process with a timeout in Rust

Rust

77

88 commits

updated May 17, 2025

See the code

README

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(())
}

Significant stargazers

llogiq

752 followers · starred Apr 2018

Martin Liška

145 followers · starred Dec 2024

Kraktus

59 followers · starred May 2022

Lukas Kalbertodt

359 followers · starred Jan 2016