D++ (DPP)
C++ Discord API Bot Library
Loading...
Searching...
No Matches
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

template<awaitable_type 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.
void emplace_value (Args &&... args)
 Construct the result in place by forwarding the arguments, and by default resume any awaiter.
final_awaiter< R > final_suspend () const noexcept
 Function called by the standard library when the coroutine reaches its last suspension point.
awaitable< R > get_awaitable ()
 Get an awaitable object for this promise.
dpp::task< R > get_return_object () noexcept
 Function called by the standard library when the coroutine is created.
std_coroutine::suspend_never initial_suspend () const noexcept
 Function called by the standard library when the coroutine is created.
void notify_awaiter ()
 Notify a currently awaiting coroutine that the result is ready.
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.
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.
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.
void set_exception (std::exception_ptr ptr)
 Set this promise to an exception and resume any awaiter.
void set_value (U &&v)
 Construct the result by forwarding reference, and resume any awaiter.
void unhandled_exception ()
 Function called by the standard library when an exception is thrown and not caught in the coroutine.

Public Attributes

std::atomic< bool > cancelled = false
 Whether the task is cancelled or not.

Protected Types

using storage_type
 Variant representing one of either 3 states of the result value : empty, result, exception.

Protected Member Functions

std_coroutine::coroutine_handle release_awaiter ()
 Unlinks this promise from its currently linked awaiter and returns it.
void throw_if_not_empty ()
 Check if the result is empty, throws otherwise.

Protected Attributes

std_coroutine::coroutine_handle awaiter
 Coroutine handle currently awaiting the completion of this promise.
std::atomic< uint8_t > state
 State of the awaitable tied to this promise.
storage_type value
 State of the result value.

Friends

struct final_awaiter< R >

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

Member Typedef Documentation

◆ storage_type

using dpp::detail::promise::promise_base< R >::storage_type
protectedinherited

Variant representing one of either 3 states of the result value : empty, result, exception.

Member Function Documentation

◆ await_transform()

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

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

◆ emplace_value()

void dpp::basic_promise< R >::emplace_value ( Args &&... args)
inlineinherited

Construct the result in place by forwarding the arguments, and by default resume any awaiter.

Template Parameters
NotifyWhether to resume any awaiter or not.
Exceptions
dpp::logic_exceptionif the promise is not empty.

◆ final_suspend()

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

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_awaitable()

awaitable< R > dpp::detail::promise::promise_base< R >::get_awaitable ( )
inlineinherited

Get an awaitable object for this promise.

Exceptions
dpp::logic_exceptionif get_awaitable has already been called on this object.
Returns
awaitable<T> An object that can be co_await-ed to retrieve the value of this promise.

◆ get_return_object()

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

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

Returns
dpp::task The coroutine object

◆ initial_suspend()

template<typename R>
std_coroutine::suspend_never dpp::detail::task::promise_base< R >::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.

◆ notify_awaiter()

void dpp::detail::promise::promise_base< R >::notify_awaiter ( )
inlineinherited

Notify a currently awaiting coroutine that the result is ready.

Note
This may resume the coroutine on the current thread.
Exceptions
?Any exception thrown by the coroutine if resumed will propagate

◆ release_awaiter()

std_coroutine::coroutine_handle dpp::detail::promise::promise_base< R >::release_awaiter ( )
inlineprotectedinherited

Unlinks this promise from its currently linked awaiter and returns it.

At the time of writing this is only used in the case of a serious internal error in dpp::task. Avoid using this as this will crash if the promise is used after this.

◆ 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

◆ set_exception()

void dpp::detail::promise::promise_base< R >::set_exception ( std::exception_ptr ptr)
inlineinherited

Set this promise to an exception and resume any awaiter.

Template Parameters
NotifyWhether to resume any awaiter or not.
Exceptions
dpp::logic_exceptionif the promise is not empty.
?Any exception thrown by the coroutine if resumed will propagate

◆ set_value()

void dpp::basic_promise< R >::set_value ( U && v)
inlineinherited

Construct the result by forwarding reference, and resume any awaiter.

Template Parameters
NotifyWhether to resume any awaiter or not.
Exceptions
dpp::logic_exceptionif the promise is not empty.

◆ throw_if_not_empty()

void dpp::detail::promise::promise_base< R >::throw_if_not_empty ( )
inlineprotectedinherited

Check if the result is empty, throws otherwise.

Exceptions
dpp::logic_exceptionif the result isn't empty.

◆ unhandled_exception()

template<typename R>
void dpp::detail::task::promise_base< R >::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

◆ final_awaiter< R >

template<typename R>
friend struct final_awaiter< R >
friend

Member Data Documentation

◆ awaiter

std_coroutine::coroutine_handle dpp::detail::promise::promise_base< R >::awaiter
protectedinherited

Coroutine handle currently awaiting the completion of this promise.

◆ cancelled

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

Whether the task is cancelled or not.

◆ state

std::atomic<uint8_t> dpp::detail::promise::promise_base< R >::state
protectedinherited

State of the awaitable tied to this promise.

◆ value

storage_type dpp::detail::promise::promise_base< R >::value
protectedinherited

State of the result value.

See also
storage_type
Note
use .index() instead of std::holds_alternative to support promise_base<std::exception_ptr> and promise_base<std::monostate> :)
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