| 26 | */ |
| 27 | template<typename Callable> |
| 28 | void Dispatch(const mitk::StorageThreadDispatcherBase::Pointer& dispatcher, Callable callable) |
| 29 | { |
| 30 | std::exception_ptr error; |
| 31 | |
| 32 | auto task = [callable, &error]() |
| 33 | { |
| 34 | try |
| 35 | { |
| 36 | callable(); |
| 37 | } |
| 38 | catch (...) |
| 39 | { |
| 40 | error = std::current_exception(); |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | if (dispatcher.IsNotNull()) |
| 45 | { |
| 46 | dispatcher->Execute(std::move(task)); |
| 47 | } |
| 48 | else |
| 49 | { |
| 50 | task(); |
| 51 | } |
| 52 | |
| 53 | if (error) |
| 54 | std::rethrow_exception(error); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | namespace mitk |
no test coverage detected