#include <task.hpp>
Public Types | |
| using | value_type = T |
Public Member Functions | |
| task (std::shared_ptr< detail::task_future< T > > future) | |
| template<typename F> | |
| auto | then (F &&f) const |
| T | get () const |
| task_state | get_state () const |
| std::exception_ptr | get_exception () const |
| 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 |
| task_awaiter | operator co_await () const |
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.