![]() |
D++ (DPP)
C++ Discord API Bot Library
|
Generic promise class, represents the owning potion of an asynchronous value. More...
#include <awaitable.h>
Inheritance diagram for dpp::basic_promise< T >:
Collaboration diagram for dpp::basic_promise< T >: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... | |
| awaitable< T > | get_awaitable () |
| Get an awaitable object for this promise. More... | |
| void | notify_awaiter () |
| Notify a currently awaiting coroutine that the result is ready. More... | |
| template<bool Notify = true> | |
| void | set_exception (std::exception_ptr ptr) |
| Set this promise to an exception 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, 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... | |
Protected Types | |
| using | storage_type = result_t< T > |
| Variant representing one of either 3 states of the result value : empty, result, exception. More... | |
Protected Member Functions | |
| std_coroutine::coroutine_handle | release_awaiter () |
| Unlinks this promise from its currently linked awaiter and returns it. More... | |
| void | throw_if_not_empty () |
| Check if the result is empty, throws otherwise. More... | |
Protected Attributes | |
| std_coroutine::coroutine_handle | awaiter = nullptr |
| Coroutine handle currently awaiting the completion of this promise. More... | |
| std::atomic< uint8_t > | state = sf_none |
| State of the awaitable tied to this promise. More... | |
| storage_type | value = std::monostate{} |
| State of the result value. More... | |
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.
| T | Type of the asynchronous value |
|
protectedinherited |
Variant representing one of either 3 states of the result value : empty, result, exception.
|
inline |
Construct the result in place by forwarding the arguments, and by default resume any awaiter.
| Notify | Whether to resume any awaiter or not. |
| dpp::logic_exception | if the promise is not empty. |
|
inlineinherited |
Get an awaitable object for this promise.
| dpp::logic_exception | if get_awaitable has already been called on this object. |
|
inlineinherited |
Notify a currently awaiting coroutine that the result is ready.
| ? | Any exception thrown by the coroutine if resumed will propagate |
|
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.
|
inlineinherited |
Set this promise to an exception and resume any awaiter.
| Notify | Whether to resume any awaiter or not. |
| dpp::logic_exception | if the promise is not empty. |
| ? | Any exception thrown by the coroutine if resumed will propagate |
|
inline |
Construct a void result, and resume any awaiter.
| Notify | Whether to resume any awaiter or not. |
| dpp::logic_exception | if the promise is not empty. |
|
inline |
Construct the result by forwarding reference, and resume any awaiter.
| Notify | Whether to resume any awaiter or not. |
| dpp::logic_exception | if the promise is not empty. |
|
inlineprotectedinherited |
Check if the result is empty, throws otherwise.
| dpp::logic_exception | if the result isn't empty. |
|
protectedinherited |
Coroutine handle currently awaiting the completion of this promise.
|
protectedinherited |
State of the awaitable tied to this promise.
|
protectedinherited |
State of the result value.