uvco 0.1
|
#include <promise_core.h>
Public Member Functions | |
PromiseCore ()=default | |
PromiseCore (const PromiseCore &)=delete | |
PromiseCore (PromiseCore &&)=delete | |
PromiseCore & | operator= (const PromiseCore &)=delete |
PromiseCore & | operator= (PromiseCore &&)=delete |
PromiseCore (T &&value) | |
virtual void | setHandle (std::coroutine_handle<> handle) |
Set the coroutine to be resumed once a result is ready. | |
void | resetHandle () |
void | cancel () |
bool | willResume () |
Checks if a coroutine is waiting on a promise belonging to this core. | |
bool | ready () const |
Checks if a value is present in the slot. | |
bool | stale () const |
virtual void | resume () |
virtual | ~PromiseCore () |
void | except (const std::exception_ptr &exc) |
Public Member Functions inherited from uvco::RefCounted< PromiseCore< T > > | |
RefCounted (const RefCounted &other)=default | |
RefCounted (RefCounted &&other) noexcept | |
RefCounted & | operator= (const RefCounted &other)=default |
RefCounted & | operator= (RefCounted &&other) noexcept |
virtual | ~RefCounted ()=default |
virtual T * | addRef () |
virtual void | delRef () |
Public Attributes | |
std::optional< std::variant< T, std::exception_ptr > > | slot |
The slot contains the result once obtained. | |
Protected Attributes | |
std::optional< std::coroutine_handle<> > | handle_ |
PromiseState | state_ = PromiseState::init |
Additional Inherited Members | |
Protected Member Functions inherited from uvco::RefCounted< PromiseCore< T > > | |
RefCounted ()=default | |
A PromiseCore
is shared among copies of promises waiting for the same coroutine. It contains a state, a result (of type T
), and potentially a coroutine_handle
of the coroutine waiting on it. Only one coroutine may await a promise, this is enforced here.
A PromiseCore is RefCounted
; this reduces the overhead of shared_ptr
by as much as 50% in Debug mode and 30% in clang Release mode. However, this is only expected to occur in promise-heavy code without involvement of libuv (such as pure channels).
The canonical way would be just using shared_ptr
, which is likely fast enough. But we're experimenting, so let's have fun.
|
default |
|
delete |
|
delete |
|
inlineexplicit |
|
inlinevirtual |
Destroys a promise core. Also destroys a coroutine if there is one suspended and has not been resumed yet. In that case, a warning is emitted ("PromiseCore destroyed without ever being resumed").
|
inline |
Cancel a promise. The awaiter, if present, will immediately receive an exception. The coroutine itself will keep running, however. (This may be changed later)
|
inline |
|
delete |
|
delete |
|
inline |
Checks if a value is present in the slot.
|
inline |
|
inlinevirtual |
Resume a suspended coroutine waiting on the associated coroutine by enqueuing it in the global event loop.
A promise core can only be resumed once.
Reimplemented in uvco::MultiPromiseCore< T >.
|
inlinevirtual |
Set the coroutine to be resumed once a result is ready.
Reimplemented in uvco::MultiPromiseCore< T >.
|
inline |
Checks if the coroutine has returned, and the results have been fetched (i.e. after co_return -> co_await).
|
inline |
Checks if a coroutine is waiting on a promise belonging to this core.
|
protected |
std::optional<std::variant<T, std::exception_ptr> > uvco::PromiseCore< T >::slot |
The slot contains the result once obtained.
|
protected |