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

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

#include "task.h"

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...
 
bool await_ready () const
 Check whether or not a call to co_await will suspend the caller. More...
 
decltype(auto) await_resume () &
 Function called by the standard library when resuming. 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...
 
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...
 
dpp::task< R > && cancel () &&noexcept
 Cancel the task, it will stop the next time it uses co_await. More...
 
dpp::task< R > & cancel () &noexcept
 Cancel the task, it will stop the next time it uses co_await. More...
 
bool done () const noexcept
 Function to check if the task has finished its execution entirely. 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...
 

Protected Attributes

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

Friends

struct promise_t< R >
 Promise type of this coroutine. 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.

References dpp::detail::task::task_base< R >::cancel(), dpp::detail::task::dangling, dpp::detail::task::done, and dpp::detail::task::task_base< R >::handle.

Here is the call graph for this function:

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

References dpp::detail::task::done, and dpp::detail::task::task_base< R >::handle.

◆ 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

References dpp::detail::task::awaited, dpp::detail::task::done, dpp::detail::task::task_base< R >::handle, and dpp::detail::task::started.

◆ 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

References dpp::detail::task::task_base< R >::handle.

◆ 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

References dpp::detail::task::task_base< R >::handle.

Referenced by dpp::detail::task::task_base< R >::~task_base().

Here is the caller graph for this function:

◆ 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.

References dpp::detail::task::done, and dpp::detail::task::task_base< R >::handle.

◆ 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

References dpp::detail::task::task_base< R >::handle.

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


The documentation for this class was generated from the following file: