Skip to content

Commit

Permalink
Merge pull request #40 from alexcrichton/update-reamde
Browse files Browse the repository at this point in the history
Update README slightly
  • Loading branch information
alexcrichton authored Feb 3, 2025
2 parents 22cb40b + 6112d81 commit 1a1c2a5
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
```

0 comments on commit 1a1c2a5

Please sign in to comment.