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

A co_await-able object handling an API call in parallel with the caller. More...

+ Inheritance diagram for dpp::async< R >:
+ Collaboration diagram for dpp::async< R >:

Public Types

using result_type = R
 The return type of the API call. Defaults to confirmation_callback_t. More...
 

Public Member Functions

template<typename Obj , typename Fun , typename... Args>
 async (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 (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 (const async &)=delete
 
 async (async &&)=default
 
asyncoperator= (const async &)=delete
 
asyncoperator= (async &&)=default
 
 ~async ()
 
bool valid () const noexcept
 Check whether this awaitable refers to a valid promise. More...
 
bool await_ready () const
 Check whether or not co_await-ing this would suspend the caller, i.e. if we have the result or not. More...
 
 requires (std::is_base_of_v< awaitable, std::remove_cv_t< Derived >>) friend awaiter< Derived & > operator co_await(Derived &obj) noexcept
 Overload of the co_await operator. More...
 
 requires (std::is_base_of_v< awaitable, std::remove_cv_t< Derived >>) friend awaiter< Derived && > operator co_await(Derived &&obj) noexcept
 Overload of the co_await operator. Returns an awaiter referencing this awaitable. More...
 

Protected Types

using shared_state = detail::promise::promise_base< R >
 
using state_flags = detail::promise::state_flags
 

Protected Member Functions

uint8_t abandon ()
 Abandons the promise. More...
 

Protected Attributes

shared_statestate_ptr
 Non-owning pointer to the promise, which must be kept alive for the entire lifetime of the awaitable. More...
 

Detailed Description

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

A co_await-able object handling an API call in parallel with the caller.

This class is the return type of the dpp::cluster::co_* methods, but it can also be created manually to wrap any async call.

Remarks
- The coroutine may be resumed in another thread, do not rely on thread_local variables.
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 the D++ Discord server.
Template Parameters
RThe return type of the API call. Defaults to confirmation_callback_t

Member Typedef Documentation

◆ result_type

template<typename R >
using dpp::async< R >::result_type = R

The return type of the API call. Defaults to confirmation_callback_t.

◆ shared_state

using dpp::awaitable< R >::shared_state = detail::promise::promise_base<R >
protectedinherited

◆ state_flags

using dpp::awaitable< R >::state_flags = detail::promise::state_flags
protectedinherited

Constructor & Destructor Documentation

◆ async() [1/4]

template<typename R >
template<typename Obj , typename Fun , typename... Args>
dpp::async< R >::async ( 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() [2/4]

template<typename R >
template<typename Fun , typename... Args>
dpp::async< R >::async ( 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() [3/4]

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

◆ async() [4/4]

template<typename R >
dpp::async< R >::async ( async< R > &&  )
default

◆ ~async()

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

Member Function Documentation

◆ abandon()

auto dpp::awaitable< R >::abandon
protectedinherited

Abandons the promise.

Set the promise's state to broken and unlinks this awaitable.

Returns
uint8_t Flags previously held before setting them to broken

◆ await_ready()

bool dpp::awaitable< R >::await_ready
inherited

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 or not

◆ operator=() [1/2]

template<typename R >
async& dpp::async< R >::operator= ( async< R > &&  )
default

◆ operator=() [2/2]

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

◆ requires() [1/2]

dpp::awaitable< R >::requires ( std::is_base_of_v< awaitable< R >, std::remove_cv_t< Derived >>  ) &
inlinenoexceptinherited

Overload of the co_await operator.

Returns
Returns an awaiter referencing this awaitable.

◆ requires() [2/2]

dpp::awaitable< R >::requires ( std::is_base_of_v< awaitable< R >, std::remove_cv_t< Derived >>  ) &&
inlinenoexceptinherited

Overload of the co_await operator. Returns an awaiter referencing this awaitable.

Returns
Returns an awaiter referencing this awaitable.

◆ valid()

bool dpp::awaitable< R >::valid
noexceptinherited

Check whether this awaitable refers to a valid promise.

Returns
bool Whether this awaitable refers to a valid promise or not

Member Data Documentation

◆ state_ptr

shared_state* dpp::awaitable< R >::state_ptr
protectedinherited

Non-owning pointer to the promise, which must be kept alive for the entire lifetime of the awaitable.

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