Trait zebra_chain::diagnostic::task::CheckForPanics

source ·
pub trait CheckForPanics: Sized {
    type Output;

    // Required method
    fn check_for_panics_with(
        self,
        panic_on_unexpected_termination: bool
    ) -> Self::Output;

    // Provided methods
    fn panic_if_task_has_finished(self) -> Self::Output { ... }
    fn panic_if_task_has_panicked(self) -> Self::Output { ... }
}
Expand description

A trait that checks a task’s return value for panics.

Required Associated Types§

source

type Output

The output type, after removing panics from Self.

Required Methods§

source

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

Check if self contains a panic payload, then panic. Also panics if panic_on_unexpected_termination is true, and self is an unexpected termination. Otherwise, return the non-panic part of self.

§Panics

If self contains a panic payload, or if we’re panicking on unexpected terminations.

Provided Methods§

source

fn panic_if_task_has_finished(self) -> Self::Output

Check if self contains a panic payload or an unexpected termination, then panic. Otherwise, return the non-panic part of self.

§Panics

If self contains a panic payload or an unexpected termination.

source

fn panic_if_task_has_panicked(self) -> Self::Output

Check if self contains a panic payload, then panic. Otherwise, return the non-panic part of self.

§Panics

If self contains a panic payload.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl CheckForPanics for JoinError

§

type Output = JoinError

The [JoinError] after resuming any panics, and logging any unexpected task cancellations.

source§

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

Resume any panics and panic on unexpected task cancellations. Always returns JoinError::Cancelled.

source§

impl<T> CheckForPanics for &mut Option<Arc<JoinHandle<T>>>
where T: Debug,

source§

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

If this is the final Arc, checks if the thread has finished, then panics if the thread panicked. Otherwise, returns the thread’s return value.

If the thread has not finished, or this is not the final Arc, returns None.

§

type Output = Option<T>

source§

impl<T> CheckForPanics for Result<T, JoinError>

This is the return type of the [JoinHandle] future.

§

type Output = Result<T, JoinError>

The [JoinHandle]’s task output, after resuming any panics, and ignoring task cancellations on shutdown.

source§

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

Returns the task result if the task finished normally. Otherwise, resumes any panics, and ignores any expected errors. Handles unexpected errors based on panic_on_unexpected_termination.

If the task finished normally, returns Some(T). If the task was cancelled, returns None.

source§

impl<T> CheckForPanics for Result<T>
where T: Debug,

source§

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

§Panics
  • if the thread panicked.
  • if the thread is cancelled, panic_on_unexpected_termination is true, and Zebra is not shutting down.

Threads can’t be cancelled except by using a panic, so there are no thread errors here. panic_on_unexpected_termination is

§

type Output = T

Implementors§