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

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

#include "async.h"

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

Public Member Functions

 async_base () noexcept
 Construct an empty async. More...
 
 async_base (async_base &&other) noexcept=default
 Move constructor. More...
 
 async_base (const async_base &)=delete
 Copy constructor is disabled. 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...
 
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...
 
 ~async_base ()
 Destructor. More...
 
bool await_ready () const noexcept
 Check whether or not co_await-ing this would suspend the caller, i.e. More...
 
R && await_resume () &&noexcept
 Function called by the standard library when the async is resumed. More...
 
R & await_resume () &noexcept
 Function called by the standard library when the async is resumed. More...
 
const R & await_resume () const &noexcept
 Function called by the standard library when the async is resumed. 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...
 
async_baseoperator= (async_base &&other) noexcept=default
 Move assignment operator. More...
 
async_baseoperator= (const async_base &)=delete
 Copy assignment is disabled. 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

References dpp::detail::async::sent, and dpp::detail::async::waiting.

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


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