pub trait WaitForPanics: Sized {
type Output;
// Required method
fn wait_for_panics_with(
self,
panic_on_unexpected_termination: bool,
) -> Self::Output;
// Provided methods
fn wait_and_panic_on_unexpected_termination(self) -> Self::Output { ... }
fn wait_for_panics(self) -> Self::Output { ... }
}
Expand description
A trait that waits for a task to finish, then handles panics and cancellations.
Required Associated Types§
Required Methods§
sourcefn wait_for_panics_with(
self,
panic_on_unexpected_termination: bool,
) -> Self::Output
fn wait_for_panics_with( self, panic_on_unexpected_termination: bool, ) -> Self::Output
Waits for self
to finish, then check if its output is:
- a panic payload: resume that panic,
- an unexpected termination:
- if
panic_on_unexpected_termination
is true, panic with that error, - otherwise, hang waiting for shutdown,
- if
- an expected termination: hang waiting for shutdown.
Otherwise, returns the task return value of self
.
§Panics
If self
contains a panic payload, or if we’re panicking on unexpected terminations.
§Hangs
If self
contains an expected or ignored termination, and we’re shutting down anyway.
Provided Methods§
sourcefn wait_and_panic_on_unexpected_termination(self) -> Self::Output
fn wait_and_panic_on_unexpected_termination(self) -> Self::Output
Waits for self
to finish, then check if its output is:
- a panic payload: resume that panic,
- an unexpected termination: panic with that error,
- an expected termination: hang waiting for shutdown.
Otherwise, returns the task return value of self
.
§Panics
If self
contains a panic payload or an unexpected termination.
§Hangs
If self
contains an expected termination, and we’re shutting down anyway.
sourcefn wait_for_panics(self) -> Self::Output
fn wait_for_panics(self) -> Self::Output
Object Safety§
Implementations on Foreign Types§
source§impl<T> WaitForPanics for &mut Option<Arc<JoinHandle<T>>>where
T: Debug,
impl<T> WaitForPanics for &mut Option<Arc<JoinHandle<T>>>where
T: Debug,
source§fn wait_for_panics_with(
self,
panic_on_unexpected_termination: bool,
) -> Self::Output
fn wait_for_panics_with( self, panic_on_unexpected_termination: bool, ) -> Self::Output
If this is the final Arc
, waits for the thread to finish, then panics if the thread
panicked. Otherwise, returns the thread’s return value.
If this is not the final Arc
, drops the handle and returns None
.
type Output = Option<T>
source§impl<T> WaitForPanics for Arc<JoinHandle<T>>where
T: Debug,
impl<T> WaitForPanics for Arc<JoinHandle<T>>where
T: Debug,
source§fn wait_for_panics_with(
self,
panic_on_unexpected_termination: bool,
) -> Self::Output
fn wait_for_panics_with( self, panic_on_unexpected_termination: bool, ) -> Self::Output
If this is the final Arc
, waits for the thread to finish, then panics if the thread
panicked. Otherwise, returns the thread’s return value.
If this is not the final Arc
, drops the handle and immediately returns None
.
type Output = Option<T>
source§impl<T> WaitForPanics for JoinHandle<T>where
T: Debug,
impl<T> WaitForPanics for JoinHandle<T>where
T: Debug,
source§impl<T> WaitForPanics for JoinHandle<T>where
T: Send + 'static,
impl<T> WaitForPanics for JoinHandle<T>where
T: Send + 'static,
source§fn wait_for_panics_with(
self,
panic_on_unexpected_termination: bool,
) -> Self::Output
fn wait_for_panics_with( self, panic_on_unexpected_termination: bool, ) -> Self::Output
Returns a future which waits for self
to finish, then checks if its output is:
- a panic payload: resume that panic,
- an unexpected termination:
- if
panic_on_unexpected_termination
is true, panic with that error, - otherwise, hang waiting for shutdown,
- if
- an expected termination: hang waiting for shutdown.
Otherwise, returns the task return value of self
.
§Panics
If self
contains a panic payload, or [JoinHandle::abort()
] has been called on self
.
§Hangs
If self
contains an expected termination, and we’re shutting down anyway.
If we’re ignoring terminations because panic_on_unexpected_termination
is false
.
Futures hang by returning Pending
and not setting a waker, so this uses minimal resources.