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

Base class of dpp::async. More...

+ Inheritance diagram for dpp::detail::async::async_base< R >:

Public Member Functions

template<typename Obj , typename Fun , typename... Args>
 async_base (Obj &&obj, Fun &&fun, Args &&... args)
 Construct an async object wrapping an object method, the call is made immediately by forwarding to std::invoke and can be awaited later to retrieve the result. More...
 
template<typename Fun , typename... Args>
 async_base (Fun &&fun, Args &&... args)
 Construct an async object wrapping an invokeable object, the call is made immediately by forwarding to std::invoke and can be awaited later to retrieve the result. More...
 
 async_base () noexcept
 Construct an empty async. Using co_await on an empty async is undefined behavior. More...
 
 ~async_base ()
 Destructor. If any callback is pending it will be aborted. More...
 
 async_base (const async_base &)=delete
 Copy constructor is disabled. More...
 
 async_base (async_base &&other) noexcept=default
 Move constructor. More...
 
async_baseoperator= (const async_base &)=delete
 Copy assignment is disabled. More...
 
async_baseoperator= (async_base &&other) noexcept=default
 Move assignment operator. More...
 
bool await_ready () const noexcept
 Check whether or not co_await-ing this would suspend the caller, i.e. if we have the result or not. More...
 
bool await_suspend (detail::std_coroutine::coroutine_handle<> caller) noexcept
 Second function called by the standard library when the object is co-awaited, if await_ready returned false. More...
 
R & await_resume () &noexcept
 Function called by the standard library when the async is resumed. Its return value is what the whole co_await expression evaluates to. More...
 
const R & await_resume () const &noexcept
 Function called by the standard library when the async is resumed. Its return value is what the whole co_await expression evaluates to. More...
 
R && await_resume () &&noexcept
 Function called by the standard library when the async is resumed. Its return value is what the whole co_await expression evaluates to. More...
 

Detailed Description

template<typename R>
class dpp::detail::async::async_base< R >

Base class of dpp::async.

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

Constructor & Destructor Documentation

◆ async_base() [1/5]

template<typename R >
template<typename Obj , typename Fun , typename... Args>
dpp::detail::async::async_base< R >::async_base ( Obj &&  obj,
Fun &&  fun,
Args &&...  args 
)
inlineexplicit

Construct an async object wrapping an object method, the call is made immediately by forwarding to std::invoke and can be awaited later to retrieve the result.

Parameters
objThe object to call the method on
funThe method of the object to call. Its last parameter must be a callback taking a parameter of type R
argsParameters to pass to the method, excluding the callback

◆ async_base() [2/5]

template<typename R >
template<typename Fun , typename... Args>
dpp::detail::async::async_base< R >::async_base ( Fun &&  fun,
Args &&...  args 
)
inlineexplicit

Construct an async object wrapping an invokeable object, the call is made immediately by forwarding to std::invoke and can be awaited later to retrieve the result.

Parameters
funThe object to call using std::invoke. Its last parameter must be a callable taking a parameter of type R
argsParameters to pass to the object, excluding the callback

◆ async_base() [3/5]

template<typename R >
dpp::detail::async::async_base< R >::async_base ( )
inlinenoexcept

Construct an empty async. Using co_await on an empty async is undefined behavior.

◆ ~async_base()

template<typename R >
dpp::detail::async::async_base< R >::~async_base ( )
inline

Destructor. If any callback is pending it will be aborted.

◆ async_base() [4/5]

template<typename R >
dpp::detail::async::async_base< R >::async_base ( const async_base< R > &  )
delete

Copy constructor is disabled.

◆ async_base() [5/5]

template<typename R >
dpp::detail::async::async_base< R >::async_base ( async_base< R > &&  other)
defaultnoexcept

Move constructor.

NOTE: Despite being marked noexcept, this function uses std::lock_guard which may throw. The implementation assumes this can never happen, hence noexcept. Report it if it does, as that would be a bug.

Remarks
Using the moved-from async after this function is undefined behavior.
Parameters
otherThe async object to move the data from.

Member Function Documentation

◆ await_ready()

template<typename R >
bool dpp::detail::async::async_base< R >::await_ready ( ) const
inlinenoexcept

Check whether or not co_await-ing this would suspend the caller, i.e. if we have the result or not.

Returns
bool Whether we already have the result of the API call or not

◆ await_resume() [1/3]

template<typename R >
R&& dpp::detail::async::async_base< R >::await_resume ( ) &&
inlinenoexcept

Function called by the standard library when the async is resumed. Its return value is what the whole co_await expression evaluates to.

Remarks
Do not call this manually, use the co_await keyword instead.
Returns
The result of the API call as an rvalue reference.

◆ await_resume() [2/3]

template<typename R >
R& dpp::detail::async::async_base< R >::await_resume ( ) &
inlinenoexcept

Function called by the standard library when the async is resumed. Its return value is what the whole co_await expression evaluates to.

Remarks
Do not call this manually, use the co_await keyword instead.
Returns
The result of the API call as an lvalue reference.

◆ await_resume() [3/3]

template<typename R >
const R& dpp::detail::async::async_base< R >::await_resume ( ) const &
inlinenoexcept

Function called by the standard library when the async is resumed. Its return value is what the whole co_await expression evaluates to.

Remarks
Do not call this manually, use the co_await keyword instead.
Returns
The result of the API call as a const lvalue reference.

◆ await_suspend()

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

Second function called by the standard library when the object is co-awaited, if await_ready returned false.

Checks again for the presence of the result, if absent, signals to suspend and keep track of the calling coroutine for the callback to resume.

Remarks
Do not call this manually, use the co_await keyword instead.
Parameters
callerThe handle to the coroutine co_await-ing and being suspended

◆ operator=() [1/2]

template<typename R >
async_base& dpp::detail::async::async_base< R >::operator= ( async_base< R > &&  other)
defaultnoexcept

Move assignment operator.

NOTE: Despite being marked noexcept, this function uses std::lock_guard which may throw. The implementation assumes this can never happen, hence noexcept. Report it if it does, as that would be a bug.

Remarks
Using the moved-from async after this function is undefined behavior.
Parameters
otherThe async object to move the data from

◆ operator=() [2/2]

template<typename R >
async_base& dpp::detail::async::async_base< R >::operator= ( const async_base< R > &  )
delete

Copy assignment is disabled.

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