D++ (DPP)
C++ Discord API Bot Library
dpp::task Class Reference

A coroutine task. It starts immediately on construction and can be co_await-ed, making it perfect for parallel coroutines returning a value. More...

Public Member Functions

 task ()=default
 Default constructor, creates a task not bound to a coroutine. More...
 
 task (const task &)=delete
 Copy constructor is disabled. More...
 
 task (task &&other) noexcept
 Move constructor, grabs another task's coroutine handle. More...
 
taskoperator= (const task &)=delete
 Copy assignment is disabled. More...
 
taskoperator= (task &&other) noexcept
 Move assignment, grabs another task's coroutine handle. More...
 
 ~task ()
 Destructor. More...
 
bool done () const noexcept
 Function to check if the task has finished its execution entirely. More...
 
taskcancel () &noexcept
 Cancel the task, it will stop the next time it uses co_await. On co_await-ing this task, throws dpp::task_cancelled_exception. More...
 
task && cancel () &&noexcept
 Cancel the task, it will stop the next time it uses co_await. On co_await-ing this task, throws dpp::task_cancelled_exception. More...
 

Protected Member Functions

 task (handle_t handle_)
 Construct from a coroutine handle. Internal use only. More...
 
void cleanup ()
 Clean up our handle, cancelling any running task. More...
 

Friends

struct detail::task::promise_t< R >
 

Detailed Description

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
RReturn type of the task. Cannot be a reference but can be void.

Constructor & Destructor Documentation

◆ task() [1/4]

dpp::task::task ( handle_t  handle_)
inlineexplicitprotected

Construct from a coroutine handle. Internal use only.

◆ task() [2/4]

dpp::task::task ( )
default

Default constructor, creates a task not bound to a coroutine.

◆ task() [3/4]

dpp::task::task ( const task )
delete

Copy constructor is disabled.

◆ task() [4/4]

dpp::task::task ( task &&  other)
inlinenoexcept

Move constructor, grabs another task's coroutine handle.

Parameters
otherTask to move the handle from

◆ ~task()

dpp::task::~task ( )
inline

Destructor.

Destroys the handle. If the task is still running, it will be cancelled.

Member Function Documentation

◆ cancel() [1/2]

task&& dpp::task::cancel ( ) &&
inlinenoexcept

Cancel the task, it will stop the next time it uses co_await. On co_await-ing this task, throws dpp::task_cancelled_exception.

Returns
*this

◆ cancel() [2/2]

task& dpp::task::cancel ( ) &
inlinenoexcept

Cancel the task, it will stop the next time it uses co_await. On co_await-ing this task, throws dpp::task_cancelled_exception.

Returns
*this

◆ cleanup()

void dpp::task::cleanup ( )
inlineprotected

Clean up our handle, cancelling any running task.

◆ done()

bool dpp::task::done ( ) const
inlinenoexcept

Function to check if the task has finished its execution entirely.

Returns
bool Whether the task is finished.

◆ operator=() [1/2]

task& dpp::task::operator= ( const task )
delete

Copy assignment is disabled.

◆ operator=() [2/2]

task& dpp::task::operator= ( task &&  other)
inlinenoexcept

Move assignment, grabs another task's coroutine handle.

Parameters
otherTask to move the handle from

Friends And Related Function Documentation

◆ detail::task::promise_t< R >

friend struct detail::task::promise_t< R >
friend
D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0