wwa-coro 0.0.1
Yet Another C++20 Coroutine Library
|
A coroutine task. More...
#include <task.h>
Public Types | |
using | const_reference = std::add_lvalue_reference_t<std::add_const_t<value_type>> |
Constant version of reference . | |
using | promise_type = detail::promise_type<Result> |
The promise type associated with the task. | |
using | reference |
Reference type; Result&& if Result is an rvalue reference, Result& otherwise. | |
using | rvalue_reference = std::add_rvalue_reference_t<std::remove_cv_t<value_type>> |
Rvalue reference type. | |
using | value_type = std::remove_reference_t<Result> |
Value type; a Result with all references stripped. | |
Public Member Functions | |
task () noexcept=default | |
Default constructor. | |
task (task &&other) noexcept | |
Move constructor. | |
~task () | |
Destructor. | |
bool | destroy () |
Destroys the task. | |
constexpr bool | is_ready () const noexcept |
Checks if the task is ready. | |
auto | operator co_await () &&noexcept |
Await the result of the task. | |
auto | operator co_await () const &noexcept |
Await the result of the task. | |
task & | operator= (task &&other) noexcept |
Move assignment operator. | |
reference | result_value () & |
Returns the result produced by the task. | |
rvalue_reference | result_value () && |
Returns the result produced by the task. | |
const_reference | result_value () const & |
Returns the result produced by the task. | |
bool | resume () const |
Resumes the task. | |
A coroutine task.
The task
class represents a coroutine task that can be used to perform asynchronous operations. A task is a lightweight object that wraps a coroutine and provides a mechanism for resuming the coroutine and obtaining the result of the operation.
Example:
Result | The type of the result produced by the task. |
using wwa::coro::task< Result >::const_reference = std::add_lvalue_reference_t<std::add_const_t<value_type>> |
using wwa::coro::task< Result >::promise_type = detail::promise_type<Result> |
The promise type associated with the task.
The promise_type
alias is a type alias for the promise type associated with the task.
using wwa::coro::task< Result >::reference |
using wwa::coro::task< Result >::rvalue_reference = std::add_rvalue_reference_t<std::remove_cv_t<value_type>> |
using wwa::coro::task< Result >::value_type = std::remove_reference_t<Result> |
|
defaultnoexcept |
Default constructor.
|
inlinenoexcept |
|
inline |
|
inline |
|
inlinenodiscardconstexprnoexcept |
Checks if the task is ready.
A task is considered ready if it has finished executing or has an empty coroutine handle associated with (for example, a default-constructed task).
A task that is ready cannot be resumed.
true | The task has finished executing; the result is available. |
|
inlinenoexcept |
|
inlinenoexcept |
Await the result of the task.
This operator allows the task to be co_await
'ed, returning the result produced by the task. If the task's result type is an rvalue reference, it returns an rvalue reference to the result. Otherwise, it returns an lvalue reference to the result.
|
inlinenoexcept |
|
inline |
Returns the result produced by the task.
Returns an lvalue or rvalue (if Result
template parameter of the task is an rvalue reference) reference to the result produced by the task.
bad_task | The task is empty or has been destroyed. |
bad_result_access | The result is not yet available. |
|
inline |
Returns the result produced by the task.
Returns an rvalue reference to the result produced by the task.
bad_task | The task is empty or has been destroyed. |
bad_result_access | The result is not yet available. |
|
inline |
Returns the result produced by the task.
Returns a constant lvalue reference to the result produced by the task.
bad_task | The task is empty or has been destroyed. |
bad_result_access | The result is not yet available. |
|
inline |
Resumes the task.
Resuming a task causes the associated coroutine to be resumed. A task can only be resumed if it is not ready.
true | The task has not yet finished executing. |
false | The task has finished executing; the result is available. |