Struct procspawn::JoinHandle
source · pub struct JoinHandle<T> { /* private fields */ }
Expand description
An owned permission to join on a process (block on its termination).
The join handle can be used to join a process but also provides the ability to kill it.
Implementations§
source§impl<T> JoinHandle<T>
impl<T> JoinHandle<T>
sourcepub fn pid(&self) -> Option<u32>
pub fn pid(&self) -> Option<u32>
Returns the process ID if available.
The process ID is unavailable when pooled calls are not scheduled to processes.
sourcepub fn kill(&mut self) -> Result<(), SpawnError>
pub fn kill(&mut self) -> Result<(), SpawnError>
Kill the child process.
If the join handle was created from a pool this call will do one of two things depending on the situation:
- if the call was already picked up by the process, the process will be killed.
- if the call was not yet scheduled to a process it will be cancelled.
sourcepub fn stdin(&mut self) -> Option<&mut ChildStdin>
pub fn stdin(&mut self) -> Option<&mut ChildStdin>
Fetch the stdin
handle if it has been captured
sourcepub fn stdout(&mut self) -> Option<&mut ChildStdout>
pub fn stdout(&mut self) -> Option<&mut ChildStdout>
Fetch the stdout
handle if it has been captured
Examples found in repository?
4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
procspawn::init();
let mut builder = procspawn::Builder::new();
builder.stdout(Stdio::piped());
let mut handle = builder.spawn((1, 2), |(a, b)| {
println!("{:?} {:?}", a, b);
});
let mut s = String::new();
handle.stdout().unwrap().read_to_string(&mut s).unwrap();
assert_eq!(s, "1 2\n");
}
sourcepub fn stderr(&mut self) -> Option<&mut ChildStderr>
pub fn stderr(&mut self) -> Option<&mut ChildStderr>
Fetch the stderr
handle if it has been captured
source§impl<T: Serialize + DeserializeOwned> JoinHandle<T>
impl<T: Serialize + DeserializeOwned> JoinHandle<T>
sourcepub fn join(self) -> Result<T, SpawnError>
pub fn join(self) -> Result<T, SpawnError>
Wait for the child process to return a result.
If the join handle was created from a pool the join is virtualized.
Examples found in repository?
More examples
3 4 5 6 7 8 9 10 11 12 13 14 15 16
fn main() {
procspawn::init();
let a = 42u32;
let b = 23u32;
let c = 1;
let handle = spawn!((a => new_name1, b, mut c) || -> Result<_, ()> {
c += 1;
Ok(new_name1 + b + c)
});
let value = handle.join().unwrap();
println!("{:?}", value);
}
71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main() {
procspawn::init();
let bytes = MyBytes::open("Cargo.toml").unwrap();
let bytes_two = procspawn::spawn!((bytes.clone() => bytes) || {
println!("length: {}", bytes.bytes.len());
bytes
})
.join()
.unwrap();
assert_eq!(bytes, bytes_two);
}
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
procspawn::init();
let handle = spawn((), |()| {
panic!("Whatever!");
});
match handle.join() {
Ok(()) => unreachable!(),
Err(err) => {
let panic = err.panic_info().expect("got a non panic error");
println!("process panicked with {}", panic.message());
println!("{:#?}", panic);
}
}
}
sourcepub fn join_timeout(&mut self, timeout: Duration) -> Result<T, SpawnError>
pub fn join_timeout(&mut self, timeout: Duration) -> Result<T, SpawnError>
Like join
but with a timeout.
Can be called multiple times. If anything other than a timeout error is returned, the
handle becomes unusuable, and subsequent calls to either join
or join_timeout
will
return an error.