uvco 0.1
Loading...
Searching...
No Matches
uvco::Promise< void > Class Reference

#include <promise.h>

Collaboration diagram for uvco::Promise< void >:

Classes

struct  PromiseAwaiter_
 Handles the actual suspension and resumption. More...

Public Types

using promise_type = Coroutine<void>

Public Member Functions

 Promise (Promise< void > &&other) noexcept
 Promise ready to be awaited or fulfilled.
Promiseoperator= (const Promise< void > &other)=delete
Promiseoperator= (Promise< void > &&other) noexcept
 Promise (const Promise< void > &other)=delete
 ~Promise ()
PromiseAwaiter_ operator co_await () const
bool ready () const
 Returns whether the promise has already been fulfilled.
void unwrap ()

Private Types

using PromiseCore_ = PromiseCore<void>

Private Member Functions

 Promise (PromiseCore_ &core)
PromiseCore< void > * core ()

Private Attributes

PromiseCore< void > * core_

Friends

class Coroutine< void >
template<typename... Ts>
class SelectSet
class Coroutine

Detailed Description

A void promise works slightly differently than a Promise<T> in that it doesn't return a value. However, aside from return_void() being implemented instead of return_value(), the mechanics are identical.

NOTE: for a transition period, Promise<void> is more efficient than Promise<T>: it does not allocate a separate PromiseCore. Instead, the PromiseCore<void> is placed in the Coroutine<void> frame, which itself is allocated anyway.

Member Typedef Documentation

◆ promise_type

using uvco::Promise< void >::promise_type = Coroutine<void>

Part of the coroutine protocol: Promise<void> is both return type and promise type.

◆ PromiseCore_

using uvco::Promise< void >::PromiseCore_ = PromiseCore<void>
private

Constructor & Destructor Documentation

◆ Promise() [1/3]

uvco::Promise< void >::Promise ( Promise< void > && other)
noexcept

Promise ready to be awaited or fulfilled.

46 : core_{other.core_} {
47 other.core_ = nullptr;
48}
PromiseCore< void > * core_
Definition promise.h:256
Definition promise.h:49
PromiseCore_ * core_
Definition promise.h:184

◆ Promise() [2/3]

uvco::Promise< void >::Promise ( const Promise< void > & other)
delete

◆ ~Promise()

uvco::Promise< void >::~Promise ( )
62 {
63 if (core_ != nullptr) {
64 core_->destroyCoroutine();
65 }
66}

◆ Promise() [3/3]

uvco::Promise< void >::Promise ( PromiseCore_ & core)
explicitprivate
45: core_{&core} {}
PromiseCore< void > * core()
Definition promise.h:251

Member Function Documentation

◆ core()

PromiseCore< void > * uvco::Promise< void >::core ( )
inlineprivate
251 {
252 BOOST_ASSERT(core_ != nullptr);
253 return core_;
254 }

◆ operator co_await()

Promise< void >::PromiseAwaiter_ uvco::Promise< void >::operator co_await ( ) const

Returns an awaiter object for the promise, handling actual suspension and resumption.

17 {
18 return PromiseAwaiter_{*core_};
19}
Handles the actual suspension and resumption.
Definition promise.h:224

◆ operator=() [1/2]

Promise & uvco::Promise< void >::operator= ( const Promise< void > & other)
delete

◆ operator=() [2/2]

Promise< void > & uvco::Promise< void >::operator= ( Promise< void > && other)
noexcept
50 {
51 if (this == &other) {
52 return *this;
53 }
54 if (core_ != nullptr) {
55 core_->destroyCoroutine();
56 }
58 other.core_ = nullptr;
59 return *this;
60}

◆ ready()

bool uvco::Promise< void >::ready ( ) const
nodiscard

Returns whether the promise has already been fulfilled.

68{ return core_->ready_; }

◆ unwrap()

void uvco::Promise< void >::unwrap ( )
70 {
71 if (ready()) {
72 if (core_->exception_) {
73 std::rethrow_exception(core_->exception_.value());
74 }
75 } else {
76 throw UvcoException(UV_EAGAIN, "unwrap called on unfulfilled promise");
77 }
78}
bool ready() const
Returns whether the promise has already been fulfilled.
Definition promise.cc:68

◆ Coroutine

friend class Coroutine
friend

◆ Coroutine< void >

friend class Coroutine< void >
friend

◆ SelectSet

template<typename... Ts>
friend class SelectSet
friend

Member Data Documentation

◆ core_

PromiseCore<void>* uvco::Promise< void >::core_
private

The documentation for this class was generated from the following files: