|
ThreadSchedule 3.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 | |
| future_with_error_handler (std::future< T > future) | |
| future_with_error_handler (future_with_error_handler const &)=delete | |
| auto | operator= (future_with_error_handler const &) -> future_with_error_handler &=delete |
| future_with_error_handler (future_with_error_handler &&)=default | |
| auto | operator= (future_with_error_handler &&) -> future_with_error_handler &=default |
| auto | on_error (std::function< void(std::exception_ptr)> callback) -> future_with_error_handler & |
| Attach an error callback. | |
| template<typename Callback , std::enable_if_t<!std::is_same_v<::threadschedule::detail::remove_cvref_t< Callback >, std::function< void(std::exception_ptr)> >, int > = 0> | |
| auto | on_error (Callback &&callback) -> future_with_error_handler & |
| 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.
future_with_error_handler<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 285 of file error_handler.hpp.
|
inlineexplicit |
Definition at line 288 of file error_handler.hpp.
|
delete |
|
default |
|
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. Exceptions from the callback are ignored so they cannot replace the original failure.
T (void when T is void). | Any | exception stored in the underlying std::future. |
Definition at line 341 of file error_handler.hpp.
|
inline |
Definition at line 320 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 309 of file error_handler.hpp.
|
default |
|
delete |
|
inline |
Check whether the future refers to a shared state.
Delegates directly to std::future::valid().
Definition at line 412 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 373 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 387 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 401 of file error_handler.hpp.