-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Why does Error require Send (and Sync)? #81
Comments
It makes anyhow::Error usable in async code. Without this, it would not be usable in async code. For example: // Not Send or Sync
struct Error(Box<dyn std::error::Error>);
async fn f() -> Result<(), Error> {
Ok(())
}
#[tokio::main]
async fn main() {
tokio::spawn(f()).await;
} error[E0277]: `(dyn std::error::Error + 'static)` cannot be sent between threads safely
--> src/main.rs:10:5
|
10 | tokio::spawn(f()).await;
| ^^^^^^^^^^^^ `(dyn std::error::Error + 'static)` cannot be sent between threads safely |
Regarding PoisonError, that is not intended to be stored in an error variant. It signals that some other thread panicked while holding the same Mutex or RwLock and that the current thread should either recover (via |
Ah, the explanation about I didn't understand the argument against Are you suggesting that the pattern of allowing for recovery from such cases is bad? This error is from a library that does not necessarily control what is done with a mutex held, so it seems legitimate to allow clients of the code to recover by passing out the guard. I understand we are off topic now, but can you please elaborate some more? |
Regarding poisons: Regarding guards: |
Thanks for the explanation! |
See title. It's not clear to me. The documentation says:
I can see that ;) But there is no explanation. I haven't found one in the source code either.
In a different issue where the suggestions was made that
The response was:
Again, no explanation. May I ask why this requirement exists?
I am asking because I am dealing with an error type that -- legitimately, in my opinion -- has a variant that contains a
PoisonError
which in turn wraps aMutexGuard
. The latter does not implementSend
, renderinganyhow
useless with those error types, from what I can tell.The text was updated successfully, but these errors were encountered: