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

A task's promise_t type, with special logic for handling nested tasks. More...

#include <task.h>

+ Inheritance diagram for dpp::detail::task::promise_t< R >:
+ Collaboration diagram for dpp::detail::task::promise_t< R >:

Public Member Functions

 ~promise_t ()
 Destructor. Destroys the value if it was constructed. More...
 
void return_value (R &&expr) noexcept(std::is_nothrow_move_constructible_v< R >)
 Function called by the standard library when the coroutine co_returns a value. More...
 
void return_value (const R &expr) noexcept(std::is_nothrow_copy_constructible_v< R >)
 Function called by the standard library when the coroutine co_returns a value. More...
 
template<typename T >
requires (!std::is_same_v<R, std::remove_cvref_t<T>> && std::convertible_to<T, R>)
void return_value (T &&expr) noexcept(std::is_nothrow_convertible_v< T, R >)
 Function called by the standard library when the coroutine co_returns a value. More...
 
dpp::task< R > get_return_object () noexcept
 Function called by the standard library when the coroutine is created. More...
 
final_awaiter< R > final_suspend () const noexcept
 Function called by the standard library when the coroutine reaches its last suspension point. More...
 
std_coroutine::suspend_never initial_suspend () const noexcept
 Function called by the standard library when the coroutine is created. More...
 
void unhandled_exception ()
 Function called by the standard library when an exception is thrown and not caught in the coroutine. More...
 
template<typename T >
auto await_transform (T &&expr) const noexcept(noexcept(co_await_resolve(std::forward< T >(expr))))
 Function called whenever co_await is used inside of the task. More...
 

Public Attributes

std::array< std::byte, sizeof(R)> result_storage
 Stored return value of the coroutine. More...
 
std::atomic< state_tstate = state_t::started
 State of the task, used to keep track of lifetime and status. More...
 
std::atomic< bool > cancelled = false
 Whether the task is cancelled or not. More...
 
detail::std_coroutine::coroutine_handle parent = nullptr
 Parent coroutine to return to for nested coroutines. More...
 

Detailed Description

template<typename R>
struct dpp::detail::task::promise_t< R >

A task's promise_t type, with special logic for handling nested tasks.

Implementation of task::promise_t for non-void return type.

Template Parameters
RReturn type of the task

Constructor & Destructor Documentation

◆ ~promise_t()

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

Destructor. Destroys the value if it was constructed.

Member Function Documentation

◆ await_transform()

template<typename T >
auto dpp::detail::task::promise_base::await_transform ( T &&  expr) const
inlinenoexceptinherited

Function called whenever co_await is used inside of the task.

Exceptions
dpp::task_cancelled_exceptionOn resumption if the task was cancelled
Returns
proxy_awaiter Returns a proxy awaiter that will check for cancellation on resumption

◆ final_suspend()

template<typename R >
final_awaiter< R > dpp::detail::task::promise_t< R >::final_suspend ( ) const
inlinenoexcept

Function called by the standard library when the coroutine reaches its last suspension point.

Returns
final_awaiter Special object containing the chain resolution and clean-up logic.

◆ get_return_object()

template<typename R >
dpp::task< R > dpp::detail::task::promise_t< R >::get_return_object ( )
inlinenoexcept

Function called by the standard library when the coroutine is created.

Returns
dpp::task The coroutine object

◆ initial_suspend()

std_coroutine::suspend_never dpp::detail::task::promise_base::initial_suspend ( ) const
inlinenoexceptinherited

Function called by the standard library when the coroutine is created.

Returns
std::suspend_never Don't suspend, the coroutine starts immediately.

◆ return_value() [1/3]

template<typename R >
void dpp::detail::task::promise_t< R >::return_value ( const R &  expr)
inlinenoexcept

Function called by the standard library when the coroutine co_returns a value.

Stores the value internally to hand to the caller when it resumes.

Parameters
exprThe value given to co_return

◆ return_value() [2/3]

template<typename R >
void dpp::detail::task::promise_t< R >::return_value ( R &&  expr)
inlinenoexcept

Function called by the standard library when the coroutine co_returns a value.

Stores the value internally to hand to the caller when it resumes.

Parameters
exprThe value given to co_return

◆ return_value() [3/3]

template<typename R >
template<typename T >
requires (!std::is_same_v<R, std::remove_cvref_t<T>> && std::convertible_to<T, R>)
void dpp::detail::task::promise_t< R >::return_value ( T &&  expr)
inlinenoexcept

Function called by the standard library when the coroutine co_returns a value.

Stores the value internally to hand to the caller when it resumes.

Parameters
exprThe value given to co_return

◆ unhandled_exception()

void dpp::detail::task::promise_base::unhandled_exception ( )
inlineinherited

Function called by the standard library when an exception is thrown and not caught in the coroutine.

Stores the exception pointer to rethrow on co_await. If the task object is destroyed and was not cancelled, throw instead

Member Data Documentation

◆ cancelled

std::atomic<bool> dpp::detail::task::promise_base::cancelled = false
inherited

Whether the task is cancelled or not.

◆ parent

detail::std_coroutine::coroutine_handle dpp::detail::task::promise_base::parent = nullptr
inherited

Parent coroutine to return to for nested coroutines.

◆ result_storage

template<typename R >
std::array<std::byte, sizeof(R)> dpp::detail::task::promise_t< R >::result_storage

Stored return value of the coroutine.

◆ state

std::atomic<state_t> dpp::detail::task::promise_base::state = state_t::started
inherited

State of the task, used to keep track of lifetime and status.

D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ 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