A coroutine task. It starts immediately on construction and can be co_await-ed, making it perfect for parallel coroutines returning a value.
More...
|
class | detail::task::task_base< R > |
| Internal use only base class containing common logic between task<R> and task<void>. It also serves to prevent await_suspend and await_resume from being used directly. More...
|
|
A coroutine task. It starts immediately on construction and can be co_await-ed, making it perfect for parallel coroutines returning a value.
- Warning
- - This feature is EXPERIMENTAL. The API may change at any time and there may be bugs. Please report any to GitHub Issues or to our Discord Server.
- Template Parameters
-
R | Return type of the task. Cannot be a reference but can be void. |
◆ task() [1/3]
Default constructor, creates a task not bound to a coroutine.
◆ task() [2/3]
dpp::task::task |
( |
const task & |
| ) |
|
|
delete |
Copy constructor is disabled.
◆ task() [3/3]
dpp::task::task |
( |
task && |
other | ) |
|
|
noexcept |
Move constructor, grabs another task's coroutine handle.
- Parameters
-
other | Task to move the handle from |
◆ ~task()
Destructor.
Destroys the handle.
- Warning
- The coroutine must be finished before this is called, otherwise it runs the risk of being resumed after it is destroyed, resuming in use-after-free undefined behavior.
◆ await_ready()
bool dpp::task::await_ready |
( |
| ) |
const |
Check whether or not a call to co_await will suspend the caller.
This function is called by the standard library as a first step when using co_await. If it returns true then the caller is not suspended.
- Exceptions
-
- Returns
- bool Whether not to suspend the caller or not
◆ cancel()
◆ done()
bool dpp::task::done |
( |
| ) |
const |
|
noexcept |
Function to check if the task has finished its execution entirely.
- Returns
- bool Whether the task is finished.
◆ operator co_await() [1/3]
auto&& dpp::task::operator co_await |
( |
| ) |
&& |
|
inlinenoexcept |
Suspend the current coroutine until the task completes.
- Exceptions
-
On | resumption, any exception thrown by the coroutine is propagated to the caller. |
- Returns
- On resumption, this expression evaluates to the result object of type R, as an rvalue reference.
◆ operator co_await() [2/3]
auto& dpp::task::operator co_await |
( |
| ) |
& |
|
inlinenoexcept |
Suspend the current coroutine until the task completes.
- Exceptions
-
On | resumption, any exception thrown by the coroutine is propagated to the caller. |
- Returns
- On resumption, this expression evaluates to the result object of type R, as a reference.
◆ operator co_await() [3/3]
const auto& dpp::task::operator co_await |
( |
| ) |
const & |
|
inlinenoexcept |
Suspend the current coroutine until the task completes.
- Exceptions
-
On | resumption, any exception thrown by the coroutine is propagated to the caller. |
- Returns
- On resumption, this expression evaluates to the result object of type R, as a const reference.
◆ operator=() [1/2]
task& dpp::task::operator= |
( |
const task & |
| ) |
|
|
delete |
Copy assignment is disabled.
◆ operator=() [2/2]
task& dpp::task::operator= |
( |
task && |
other | ) |
|
|
noexcept |
Move assignment, grabs another task's coroutine handle.
- Parameters
-
other | Task to move the handle from |
◆ detail::task::task_base< R >
Internal use only base class containing common logic between task<R> and task<void>. It also serves to prevent await_suspend and await_resume from being used directly.
- Warning
- For internal use only, do not use.
- See also
- operator co_await()