Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GUI2/Loading Screen: handle throwing exceptions from the future
Despite having exception handing in process(), the loading screen is only designed to handle one exception from the worker. If such an exception propagates to the worker, the loading screen would rethrow it in process(). It turns out we don't need an exception_ptr, since the exception would already be stored in the future returned from std::async. Fetching it with get() causes it to be rethrown at that point, same as before. Do note we do not want to simply call get() and wait, since that essentially calls future::wait() instead of future::wait_for() and would halt the main thread while it waits for the worker. Hence, we still manually check its status before fetching the exception (if any). As a bonus, it means we can use future::valid() as a check for whether the worker is still running in the dtor, since calling get() sets future::valid() to false. Any premature exit of the loading screen after the worker thread is created or its exception is handled in the finally process() loop will trigger the safe_exit call.
- Loading branch information