#include <task.hpp>
Public Types | |
| using | value_type = T |
Public Member Functions | |
| task ()=default | |
| task (std::shared_ptr< detail::task_future< T > > future) | |
| bool | valid () const |
| template<typename F> | |
| auto | then (F &&f) const |
| T | get () const |
| template<typename U = T, typename = typename std::enable_if<std::is_void<U>::value>::type> | |
| void | set_value () |
| template<typename U = T, typename = typename std::enable_if<not std::is_void<U>::value>::type> | |
| void | set_value (U &&value) |
| task_state | get_state () const |
| std::exception_ptr | get_exception () const |
| void | set_exception (std::exception_ptr exception) |
| void | wait () const |
| template<class Rep, class Period> | |
| bool | wait_for (const std::chrono::duration< Rep, Period > &timeout_duration) const |
| template<class Clock, class Duration> | |
| bool | wait_until (const std::chrono::time_point< Clock, Duration > &timeout_time) const |
| operator task< void > () const | |
| template<typename U, typename = typename std::enable_if<std::is_convertible<T, U>::value>::type> | |
| operator task< U > () const | |
| task_awaiter | operator co_await () const |
Static Public Member Functions | |
| static task | create_pending () |
| template<typename U = T, typename = typename std::enable_if<std::is_void<U>::value>::type> | |
| static task | create_ready () |
| template<typename U = T, typename = typename std::enable_if<not std::is_void<U>::value>::type> | |
| static task | create_ready (U &&value) |
| static task | create_failed (std::exception_ptr exception) |
This template class represents asynchronous tasks that run in dispatch queues.
Similar to std::shared_future, but with the addition of support for continuations (then), checking for task state (get_state) and built-in C++20 coroutine support (operator co_await).
All methods are thread-safe.
| using dispatch_queue::task< T >::value_type = T |
|
default |
Default-constructed tasks are invalid and don't hold any shared state.
|
inline |
|
inlinestatic |
Creates a failed task<T> with the passed exception.
|
inlinestatic |
Creates a pending task.
|
inlinestatic |
Creates a ready task<void>.
|
inlinestatic |
Creates a ready task<T> with the passed value.
|
inline |
Waits until the task's value is ready (by calling wait), then returns the stored value.
| ... | If the task failed with an exception, rethrows the exception instead. |
| task_error | Thrown when the task is invalid (get_state() == task_state::invalid). |
|
inline |
Returns the exception thrown while running task, if there's any.
|
inline |
Returns the task state.
|
inline |
Returns an awaiter that resumes coroutines on the task's continuation.
|
inlineexplicit |
Convert to task of convertible type.
|
inline |
Convert valued task to void task.
|
inline |
Mark a pending task as failed with the specified exception.
| task_error | Thrown if task is not pending. |
|
inline |
Mark a pending task as ready.
| task_error | Thrown if task is not pending. |
|
inline |
Mark a pending task as ready with the specified value.
| task_error | Thrown if task is not pending. |
|
inline |
Add a continuation f that is guaranteed to run after this task finishes.
If the task is not finished yet, f will run right after the task finishes in the same thread where the task ran. Otherwise, f will run immediately in the calling thread.
| task_error | Thrown when the task is invalid (get_state() == task_state::invalid) |
|
inline |
Checks if the task refers to a shared state.
|
inline |
Waits until the task is either ready or failed with an exception.
If the task is pending (get_state() == task_state::pending), blocks indefinitely until task finishes. Otherwise returns immediately without blocking.
| task_error | Thrown when the task is invalid (get_state() == task_state::invalid) |
|
inline |
Waits for at most timeout_duration until the task is either ready or failed with an exception.
If the task is pending (get_state() == task_state::pending), blocks until task finishes or until the specified timeout_duration has elapsed. Otherwise returns immediately without blocking.
true if the task is finished, otherwise false.| task_error | Thrown when the task is invalid (get_state() == task_state::invalid) |
|
inline |
Waits until timeout_time has been reached or until the task is either ready or failed with an exception, whichever comes first.
If the task is pending (get_state() == task_state::pending), blocks until task finishes or until the specified timeout_time has been reached. Otherwise returns immediately without blocking.
true if the task is finished, otherwise false.| task_error | Thrown when the task is invalid (get_state() == task_state::invalid) |