zebra_chain::diagnostic::task

Trait WaitForPanics

source
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§

source

type Output

The underlying task output, after removing panics and unwrapping termination results.

Required Methods§

source

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,
  • 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§

source

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.

source

fn wait_for_panics(self) -> Self::Output

Waits for self to finish, then check if its output is:

  • a panic payload: resume that panic,
  • a task termination: hang waiting for shutdown.

Otherwise, returns the task return value of self.

§Panics

If self contains a panic payload.

§Hangs

If self contains a task termination.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

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

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.

source§

type Output = Option<T>

source§

impl<T> WaitForPanics for Arc<JoinHandle<T>>
where T: Debug,

source§

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.

source§

type Output = Option<T>

source§

impl<T> WaitForPanics for JoinHandle<T>
where T: Debug,

source§

fn wait_for_panics_with( self, panic_on_unexpected_termination: bool, ) -> Self::Output

Waits for the thread to finish, then panics if the thread panicked.

source§

type Output = T

source§

impl<T> WaitForPanics for JoinHandle<T>
where T: Send + 'static,

source§

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,
  • 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.

source§

type Output = Pin<Box<dyn Future<Output = T> + Send>>

Implementors§