https://github.com/alexcrichton/wait-timeout
Waiting on a child process with a timeout in Rust
https://github.com/alexcrichton/wait-timeout
Last synced: about 2 months ago
JSON representation
Waiting on a child process with a timeout in Rust
- Host: GitHub
- URL: https://github.com/alexcrichton/wait-timeout
- Owner: alexcrichton
- License: apache-2.0
- Created: 2015-09-08T00:26:36.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2025-02-03T14:58:45.000Z (5 months ago)
- Last Synced: 2025-05-03T02:52:18.853Z (2 months ago)
- Language: Rust
- Size: 621 KB
- Stars: 69
- Watchers: 4
- Forks: 18
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# wait-timeout
[](https://github.com/alexcrichton/wait-timeout/actions/workflows/main.yml)
[Documentation](https://docs.rs/wait-timeout)
Rust crate for waiting on a `Child` process with a timeout specified.
```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(())
}
```