diff --git a/README.md b/README.md index 0682a1f..979d243 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,31 @@ Rust crate for waiting on a `Child` process with a timeout specified. -```toml -# Cargo.toml -[dependencies] -wait-timeout = "0.1.5" +```sh +$ cargo add wait-timeout +``` + +Example: + +```rust +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(()) +} ```