Box<dyn Error> not Send when using thread::spawn
I have a function returning Result<(), Box<dyn Error>> and I call it inside std::thread::spawn. Compiler says:
error[E0277]: dyn Error cannot be sent between threads safely
--> src/worker.rs:14:21
|
14 | thread::spawn(move || -> Result<(), Box<dyn Error>> { ... });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ closure may outlive the current function
How do people usually return errors from spawned threads? Do I need Box<dyn Error + Send + Sync> everywhere?
4 replies