|
ThreadSchedule 1.0.0
Modern C++ thread management library
|
A move-only future wrapper that supports an error callback. More...
#include <error_handler.hpp>
Public Member Functions | |
| FutureWithErrorHandler (std::future< T > future) | |
| FutureWithErrorHandler (FutureWithErrorHandler const &)=delete | |
| auto | operator= (FutureWithErrorHandler const &) -> FutureWithErrorHandler &=delete |
| FutureWithErrorHandler (FutureWithErrorHandler &&)=default | |
| auto | operator= (FutureWithErrorHandler &&) -> FutureWithErrorHandler &=default |
| auto | on_error (std::function< void(std::exception_ptr)> callback) -> FutureWithErrorHandler & |
| Attach an error callback. | |
| auto | get () -> T |
| Retrieve the result, invoking the error callback on failure. | |
| void | wait () const |
| Block until the result is ready. | |
| template<typename Rep, typename Period> | |
| auto | wait_for (std::chrono::duration< Rep, Period > const &timeout_duration) const |
| Block until the result is ready or the timeout elapses. | |
| template<typename Clock, typename Duration> | |
| auto | wait_until (std::chrono::time_point< Clock, Duration > const &timeout_time) const |
| Block until the result is ready or the given time point is reached. | |
| auto | valid () const -> bool |
| Check whether the future refers to a shared state. | |
A move-only future wrapper that supports an error callback.
FutureWithErrorHandler<T> wraps a std::future<T> and adds an optional error callback that fires when get() encounters an exception.
| T | The value type of the underlying future. |
std::future, this type is move-only (copy construction and copy assignment are deleted).std::future::valid(). Definition at line 294 of file error_handler.hpp.
|
inlineexplicit |
Definition at line 297 of file error_handler.hpp.
|
inline |
Retrieve the result, invoking the error callback on failure.
If the underlying future holds an exception, the error callback (if any) is called before the exception is re-thrown to the caller.
T. | Any | exception stored in the underlying std::future. |
Definition at line 333 of file error_handler.hpp.
|
inline |
Attach an error callback.
The callback will be invoked with the current std::exception_ptr if get() encounters an exception. Only one callback is stored; calling on_error() again replaces the previous callback.
| callback | Callable invoked with the exception pointer on failure. |
*this, allowing fluent chaining. Definition at line 317 of file error_handler.hpp.
|
inlinenodiscard |
Check whether the future refers to a shared state.
Delegates directly to std::future::valid().
Definition at line 390 of file error_handler.hpp.
|
inline |
Block until the result is ready.
Does not trigger the error callback regardless of the stored state.
Definition at line 354 of file error_handler.hpp.
|
inline |
Block until the result is ready or the timeout elapses.
Does not trigger the error callback.
std::future_status indicating whether the result is ready. Definition at line 367 of file error_handler.hpp.
|
inline |
Block until the result is ready or the given time point is reached.
Does not trigger the error callback.
std::future_status indicating whether the result is ready. Definition at line 380 of file error_handler.hpp.