Skip to content

Waiting on a child process with a timeout in Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

alexcrichton/wait-timeout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages