Skip to content

Instantly share code, notes, and snippets.

@Akanoa
Created July 19, 2022 14:36
Show Gist options
  • Save Akanoa/8537a5bc22a328937bc26269e6c86187 to your computer and use it in GitHub Desktop.
Save Akanoa/8537a5bc22a328937bc26269e6c86187 to your computer and use it in GitHub Desktop.
Unwind a panicking future
[package]
name = "async-panic"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
futures = "0.3.21"
tokio = { version = "1.20.0", features = ["full"] }
use std::panic;
use std::panic::AssertUnwindSafe;
use futures::FutureExt;
#[tokio::test]
async fn run() {
let result = AssertUnwindSafe(will_panic()).catch_unwind().await;
if let Err(e) = result {
panic::resume_unwind(e);
}
assert!(true)
}
async fn will_panic() {
assert_eq!(1, 0, "0 not equal 1")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment