async-rs / async-rs/async-std

Unbable to catch panics in a spawned task

Open
#1,052 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.1k
Forks
339
PR merge metrics
No merged PRs in 30d

Description

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(fut: F) -> task::JoinHandle<()>
where
F: Future> + Send + 'static,
{
task::spawn(async move {
if let Err(e) = fut.await {
eprintln!("{}", e)
}
})
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.