Created
July 19, 2022 14:36
-
-
Save Akanoa/8537a5bc22a328937bc26269e6c86187 to your computer and use it in GitHub Desktop.
Unwind a panicking future
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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