Enum tokio::runtime::UnhandledPanic
source · [−]#[non_exhaustive]
pub enum UnhandledPanic {
Ignore,
ShutdownRuntime,
}
rt
and tokio_unstable
only.Expand description
How the runtime should respond to unhandled panics.
Instances of UnhandledPanic
are passed to Builder::unhandled_panic
to configure the runtime behavior when a spawned task panics.
See Builder::unhandled_panic
for more details.
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
Ignore
The runtime should ignore panics on spawned tasks.
The panic is forwarded to the task’s JoinHandle
and all spawned
tasks continue running normally.
This is the default behavior.
Examples
use tokio::runtime::{self, UnhandledPanic};
let rt = runtime::Builder::new_current_thread()
.unhandled_panic(UnhandledPanic::Ignore)
.build()
.unwrap();
let task1 = rt.spawn(async { panic!("boom"); });
let task2 = rt.spawn(async {
// This task completes normally
"done"
});
rt.block_on(async {
// The panic on the first task is forwarded to the `JoinHandle`
assert!(task1.await.is_err());
// The second task completes normally
assert!(task2.await.is_ok());
})
ShutdownRuntime
The runtime should immediately shutdown if a spawned task panics.
The runtime will immediately shutdown even if the panicked task’s
JoinHandle
is still available. All further spawned tasks will be
immediately dropped and call to Runtime::block_on
will panic.
Examples
use tokio::runtime::{self, UnhandledPanic};
let rt = runtime::Builder::new_current_thread()
.unhandled_panic(UnhandledPanic::ShutdownRuntime)
.build()
.unwrap();
rt.spawn(async { panic!("boom"); });
rt.spawn(async {
// This task never completes.
});
rt.block_on(async {
// Do some work
})
Trait Implementations
sourceimpl Clone for UnhandledPanic
impl Clone for UnhandledPanic
sourcefn clone(&self) -> UnhandledPanic
fn clone(&self) -> UnhandledPanic
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl RefUnwindSafe for UnhandledPanic
impl Send for UnhandledPanic
impl Sync for UnhandledPanic
impl Unpin for UnhandledPanic
impl UnwindSafe for UnhandledPanic
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more