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

Generic promise class, represents the owning potion of an asynchronous value. More...

#include <awaitable.h>

Public Member Functions

template<bool Notify = true, typename... Args>
requires (std::constructible_from<T, Args...>)
void emplace_value (Args &&... args)
 Construct the result in place by forwarding the arguments, and by default resume any awaiter. More...
 
template<bool Notify = true, typename U = T>
requires (std::convertible_to<U&&, T>)
void set_value (U &&v)
 Construct the result by forwarding reference, and resume any awaiter. More...
 
template<bool Notify = true>
requires (std::is_void_v<T>)
void set_value ()
 Construct a void result, and resume any awaiter. More...
 
template<bool Notify = true>
void set_exception (std::exception_ptr ptr)
 
void notify_awaiter ()
 Notify a currently awaiting coroutine that the result is ready. More...
 
awaitable< T > get_awaitable ()
 Get an awaitable object for this promise. More...
 

Detailed Description

template<typename T>
class dpp::moveable_promise< T >

Generic promise class, represents the owning potion of an asynchronous value.

This class is roughly equivalent to std::promise, with the crucial distinction that the promise IS the shared state. As such, the promise needs to be kept alive for the entire time a value can be retrieved.

The difference between basic_promise and this object is that this one is moveable as it wraps an underlying basic_promise in a std::unique_ptr.

See also
awaitable

Member Function Documentation

◆ emplace_value()

template<typename T >
template<bool Notify = true, typename... Args>
requires (std::constructible_from<T, Args...>)
void dpp::moveable_promise< T >::emplace_value ( Args &&...  args)
inline

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.

◆ get_awaitable()

template<typename T >
awaitable< T > dpp::moveable_promise< T >::get_awaitable ( )
inline

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.

◆ notify_awaiter()

template<typename T >
void dpp::moveable_promise< T >::notify_awaiter ( )
inline

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

◆ set_exception()

template<typename T >
template<bool Notify = true>
void dpp::moveable_promise< T >::set_exception ( std::exception_ptr  ptr)
inline

◆ set_value() [1/2]

template<typename T >
template<bool Notify = true>
requires (std::is_void_v<T>)
void dpp::moveable_promise< T >::set_value ( )
inline

Construct a void result, and resume any awaiter.

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

◆ set_value() [2/2]

template<typename T >
template<bool Notify = true, typename U = T>
requires (std::convertible_to<U&&, T>)
void dpp::moveable_promise< T >::set_value ( U &&  v)
inline

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.
D++ Library version 10.0.31D++ 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