On multithreading and error handling

For non-recoverable user-facing errors (ie. "Cannot connect to the internet"), is returning a result through a channel to the GUI thread something ok to do? Or should I be handling it differently?

Returning the error through the channel is one reasonable way to handle errors.

That works, but IMO is needlessly complex.

What I would recommend instead:

In the main thread, you want to start all the threads, and then join on the handles of all of them

If you want to get rid of that expect() , you would have to do something like https://github.com/crev-dev/cargo-crev/blob/88b96096b7b996ad64f42f05031c871c67bbd21f/cargo-crev/src/main.rs#L1032 to get the panic error message from inside that opaque data structure via downcasting.

Each thread you join on, should be a loop either over channel recv or just checking some atomic boolean flag to make it exit.

If you can't have the thread cleanly stop, just don't join on it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.