Skip to content

Commit

Permalink
improvement: Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Dec 3, 2019
1 parent 601ff57 commit 66d051e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
17 changes: 13 additions & 4 deletions README.md
Expand Up @@ -18,17 +18,26 @@ fn main() {
spawn_sleeper("3", "3"),
spawn_sleeper("4", "2"),
spawn_sleeper("5", "1"),
).unwrap();
)
.unwrap();
})
}

async fn spawn_sleeper(id: &str, timeout: &str) -> io::Result<()> {
println!("started job {}", id);
let child = Command::new("/bin/sleep").arg(timeout).spawn().unwrap();
PidFd::from(child).await?;
println!("finished job {}", id);

let exit_status = Command::new("/bin/sleep")
.arg(timeout)
.spawn()
.map(|child| PidFd::from(&child))
.unwrap()
.into_future()
.await?;

println!("finished job {}: {}", id, exit_status);
Ok(())
}

```

## License
Expand Down
11 changes: 8 additions & 3 deletions examples/example.rs
Expand Up @@ -21,10 +21,15 @@ fn main() {

async fn spawn_sleeper(id: &str, timeout: &str) -> io::Result<()> {
println!("started job {}", id);
let child = Command::new("/bin/sleep").arg(timeout).spawn().unwrap();

PidFd::from(&child).into_future().await?;
let exit_status = Command::new("/bin/sleep")
.arg(timeout)
.spawn()
.map(|child| PidFd::from(&child))
.unwrap()
.into_future()
.await?;

println!("finished job {}", id);
println!("finished job {}: {}", id, exit_status);
Ok(())
}

0 comments on commit 66d051e

Please sign in to comment.