D++ (DPP)
C++ Discord API Bot Library
dpp::detail::task::task_base< R > Class Template Reference

Base class of dpp::task. More...

+ Collaboration diagram for dpp::detail::task::task_base< R >:

Public Member Functions

 task_base ()=default
 Default constructor, creates a task not bound to a coroutine. More...
 
 task_base (const task_base &)=delete
 Copy constructor is disabled. More...
 
 task_base (task_base &&other) noexcept
 Move constructor, grabs another task's coroutine handle. More...
 
 ~task_base ()
 Destructor. More...
 
task_baseoperator= (const task_base &)=delete
 Copy assignment is disabled. More...
 
task_baseoperator= (task_base &&other) noexcept
 Move assignment, grabs another task's coroutine handle. More...
 
bool await_ready () const
 Check whether or not a call to co_await will suspend the caller. More...
 
bool await_suspend (std_coroutine::coroutine_handle<> caller) noexcept
 Second function called by the standard library when the task is co_await-ed, if await_ready returned false. More...
 
bool done () const noexcept
 Function to check if the task has finished its execution entirely. More...
 
dpp::task< R > & 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...
 
dpp::task< R > && 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...
 
decltype(auto) await_resume () &
 Function called by the standard library when resuming. More...
 
decltype(auto) await_resume () const &
 Function called by the standard library when resuming. More...
 
decltype(auto) await_resume () &&
 Function called by the standard library when resuming. More...
 

Protected Attributes

handle_t< R > handle
 The coroutine handle of this task. More...
 

Friends

struct promise_t< R >
 Promise type of this coroutine. For internal use only, do not use. More...
 

Detailed Description

template<typename R>
class dpp::detail::task::task_base< R >

Base class of dpp::task.

Warning
This class should not be used directly by a user, use dpp::task instead.
Note
This class contains all the functions used internally by co_await. It is intentionally opaque and a private base of dpp::task so a user cannot call await_suspend() and await_resume() directly.

Constructor & Destructor Documentation

◆ task_base() [1/3]

template<typename R >
dpp::detail::task::task_base< R >::task_base ( )
default

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

◆ task_base() [2/3]

template<typename R >
dpp::detail::task::task_base< R >::task_base ( const task_base< R > &  )
delete

Copy constructor is disabled.

◆ task_base() [3/3]

template<typename R >
dpp::detail::task::task_base< R >::task_base ( task_base< R > &&  other)
inlinenoexcept

Move constructor, grabs another task's coroutine handle.

Parameters
otherTask to move the handle from

◆ ~task_base()

template<typename R >
dpp::detail::task::task_base< R >::~task_base ( )
inline

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.

Member Function Documentation

◆ await_ready()

template<typename R >
bool dpp::detail::task::task_base< R >::await_ready ( ) const
inline

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
logic_exceptionif the task is empty.
Returns
bool Whether not to suspend the caller or not

◆ await_resume() [1/3]

template<typename R >
decltype(auto) dpp::detail::task::task_base< R >::await_resume ( ) &
inline

Function called by the standard library when resuming.

Returns
Return value of the coroutine, handed to the caller of co_await.

◆ await_resume() [2/3]

template<typename R >
decltype(auto) dpp::detail::task::task_base< R >::await_resume ( ) &&
inline

Function called by the standard library when resuming.

Returns
Return value of the coroutine, handed to the caller of co_await.

◆ await_resume() [3/3]

template<typename R >
decltype(auto) dpp::detail::task::task_base< R >::await_resume ( ) const &
inline

Function called by the standard library when resuming.

Returns
Return value of the coroutine, handed to the caller of co_await.

◆ await_suspend()

template<typename R >
bool dpp::detail::task::task_base< R >::await_suspend ( std_coroutine::coroutine_handle<>  caller)
inlinenoexcept

Second function called by the standard library when the task is co_await-ed, if await_ready returned false.

Stores the calling coroutine in the promise to resume when this task suspends.

Remarks
Do not call this manually, use the co_await keyword instead.
Parameters
callerThe calling coroutine, now suspended
Returns
bool Whether to suspend the caller or not

◆ cancel() [1/2]

template<typename R >
dpp::task<R>&& dpp::detail::task::task_base< R >::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]

template<typename R >
dpp::task<R>& dpp::detail::task::task_base< R >::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

◆ done()

template<typename R >
bool dpp::detail::task::task_base< R >::done ( ) const
inlinenoexcept

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

Returns
bool Whether the task is finished.

◆ operator=() [1/2]

template<typename R >
task_base& dpp::detail::task::task_base< R >::operator= ( const task_base< R > &  )
delete

Copy assignment is disabled.

◆ operator=() [2/2]

template<typename R >
task_base& dpp::detail::task::task_base< R >::operator= ( task_base< R > &&  other)
inlinenoexcept

Move assignment, grabs another task's coroutine handle.

Parameters
otherTask to move the handle from

Friends And Related Function Documentation

◆ promise_t< R >

template<typename R >
friend struct promise_t< R >
friend

Promise type of this coroutine. For internal use only, do not use.

Member Data Documentation

◆ handle

template<typename R >
handle_t<R> dpp::detail::task::task_base< R >::handle
protected

The coroutine handle of this task.

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