Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbable to catch panics in a spawned task #1052

Open
rtumac opened this issue Jan 14, 2023 · 1 comment
Open

Unbable to catch panics in a spawned task #1052

rtumac opened this issue Jan 14, 2023 · 1 comment

Comments

@rtumac
Copy link

rtumac commented Jan 14, 2023

I am using the spawn_and_log_error function from the a-chat example. Unfortunately, this function is not able to capture panics in the spawned tasked. The async-std book mentions that catching panics in the spawned task and reacting with custom behavior is possible. If using spawn_and_log_error is the wrong approach to achieve that, could someone point me in the right direction?

fn spawn_and_log_error<F>(fut: F) -> task::JoinHandle<()>
where
    F: Future<Output = Result<()>> + Send + 'static,
{
    task::spawn(async move {
        if let Err(e) = fut.await {
            eprintln!("{}", e)
        }
    })
}
@notgull
Copy link
Contributor

notgull commented Jan 14, 2023

smol-rs/async-task#37 (not yet published) would probably resolve this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants