pub struct CheckedJoinHandle<T, P> { /* private fields */ }
Expand description
Wraps std::thread::JoinHandle
for panic value discrimination.
A CheckedJoinHandle
works like a standard JoinHandle
,
except that its join()
method dynamically checks the type of
the possible panic value for matching the type that is the
parameter of the Context
this handle was obtained from,
and if the type matches, returns the resolved value in the
“successful panic” result variant.
See the documentation of the join()
method for details and
an example of use.
Implementations§
Source§impl<T, P: Any> CheckedJoinHandle<T, P>
impl<T, P: Any> CheckedJoinHandle<T, P>
Sourcepub fn join(self) -> Result<Outcome<T, P>>
pub fn join(self) -> Result<Outcome<T, P>>
Works like std::thread::JoinHandle::join()
, except that when
the child thread’s panic value is of the expected type, it is
returned in Ok(Outcome::Panicked(_))
. If the child thread’s
closure returns normally, its return value is returned in
Ok(Outcome::NoPanic(_))
§Examples
use panic_control::{Context, Outcome};
use std::thread;
#[derive(Debug, PartialEq, Eq)]
struct Expected(pub u32);
let ctx = Context::<Expected>::new();
let h = ctx.spawn(|| {
panic!(Expected(42));
});
let outcome = h.join().unwrap();
match outcome {
Outcome::Panicked(Expected(n)) => {
println!("thread panicked as expected with {}", n);
}
_ => panic!("unexpected return value from join()")
}
Source§impl<T, P> CheckedJoinHandle<T, P>
impl<T, P> CheckedJoinHandle<T, P>
Sourcepub fn as_thread_join_handle(&self) -> &JoinHandle<T>
pub fn as_thread_join_handle(&self) -> &JoinHandle<T>
Returns a reference to the underlying JoinHandle
.
Sourcepub fn into_thread_join_handle(self) -> JoinHandle<T>
pub fn into_thread_join_handle(self) -> JoinHandle<T>
Converts into the underlying JoinHandle
,
giving up panic discrimination.