Enum tokio::runtime::UnhandledPanic
source · #[non_exhaustive]pub enum UnhandledPanic {
Ignore,
ShutdownRuntime,
}
Available on crate feature
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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
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§
source§impl Clone for UnhandledPanic
impl Clone for UnhandledPanic
source§fn clone(&self) -> UnhandledPanic
fn clone(&self) -> UnhandledPanic
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl RefUnwindSafe for UnhandledPanic
impl Send for UnhandledPanic
impl Sync for UnhandledPanic
impl Unpin for UnhandledPanic
impl UnwindSafe for UnhandledPanic
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more