uvco 0.1
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
uvco::Promise< void > Class Reference

#include <promise.h>

Collaboration diagram for uvco::Promise< void >:
Collaboration graph
[legend]

Classes

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

Public Types

using promise_type = Coroutine<void>
 

Public Member Functions

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

Private Types

using SharedCore_ = PromiseCore<void> *
 

Private Member Functions

 Promise (SharedCore_ core)
 
SharedCore_core ()
 

Private Attributes

SharedCore_ core_
 

Friends

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

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.

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.

◆ SharedCore_

using uvco::Promise< void >::SharedCore_ = PromiseCore<void> *
private

Constructor & Destructor Documentation

◆ Promise() [1/4]

uvco::Promise< void >::Promise ( )

Promise ready to be awaited or fulfilled.

47: core_{makeRefCounted<PromiseCore<void>>()} {}
SharedCore_ core_
Definition promise.h:283

◆ Promise() [2/4]

uvco::Promise< void >::Promise ( Promise< void > &&  other)
noexcept
49 : core_{other.core_} {
50 other.core_ = nullptr;
51}

◆ Promise() [3/4]

uvco::Promise< void >::Promise ( const Promise< void > &  other)
77 : core_{other.core_->addRef()} {}
virtual T * addRef()
Definition internal_utils.h:109

◆ ~Promise()

uvco::Promise< void >::~Promise ( )
79 {
80 if (core_ != nullptr) {
81 core_->delRef();
82 }
83}
virtual void delRef()
Definition internal_utils.h:117

◆ Promise() [4/4]

uvco::Promise< void >::Promise ( SharedCore_  core)
explicitprivate
48: core_{core->addRef()} {}
SharedCore_ & core()
Definition promise.h:281

Member Function Documentation

◆ core()

SharedCore_ & uvco::Promise< void >::core ( )
inlineprivate
281{ return core_; }

◆ handle()

PromiseHandle< void > uvco::Promise< void >::handle ( )
97 {
98 return PromiseHandle<void>{core_};
99}

◆ 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.

19 {
20 return PromiseAwaiter_{*core_};
21}

◆ operator=() [1/2]

Promise< void > & uvco::Promise< void >::operator= ( const Promise< void > &  other)
53 {
54 if (this == &other) {
55 return *this;
56 }
57 if (core_ != nullptr) {
58 core_->delRef();
59 }
60 core_ = other.core_->addRef();
61 return *this;
62}

◆ operator=() [2/2]

Promise< void > & uvco::Promise< void >::operator= ( Promise< void > &&  other)
noexcept
64 {
65 if (this == &other) {
66 return *this;
67 }
68 if (core_ != nullptr) {
69 core_->delRef();
70 }
71 core_ = other.core_;
72 other.core_ = nullptr;
73 return *this;
74}

◆ ready()

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

Returns whether the promise has already been fulfilled.

85{ return core_->ready_; }
bool ready_
Definition promise_core.h:226

◆ unwrap()

void uvco::Promise< void >::unwrap ( )
87 {
88 if (ready()) {
89 if (core_->exception_) {
90 std::rethrow_exception(core_->exception_.value());
91 }
92 } else {
93 throw UvcoException(UV_EAGAIN, "unwrap called on unfulfilled promise");
94 }
95}
std::optional< std::exception_ptr > exception_
Contains the exception if thrown.
Definition promise_core.h:229
bool ready() const
Returns whether the promise has already been fulfilled.
Definition promise.cc:85

Friends And Related Symbol Documentation

◆ Coroutine< void >

friend class Coroutine< void >
friend

◆ SelectSet

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

Member Data Documentation

◆ core_

SharedCore_ uvco::Promise< void >::core_
private

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