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

#include <promise_core.h>

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

Public Member Functions

 PromiseCore ()=default
 
 PromiseCore (const PromiseCore &)=delete
 
 PromiseCore (PromiseCore &&)=delete
 
PromiseCore< void > & operator= (const PromiseCore &)=delete
 
PromiseCore< void > & operator= (PromiseCore &&)=delete
 
 ~PromiseCore () override
 
void cancel ()
 See PromiseCore::cancel.
 
void setHandle (std::coroutine_handle<> handle)
 See PromiseCore::set_resume.
 
void resetHandle ()
 See PromiseCore::resetHandle.
 
bool willResume () const
 See PromiseCore::willResume.
 
bool ready () const
 See PromiseCore::ready.
 
bool stale () const
 See PromiseCore::stale.
 
void resume ()
 See PromiseCore::resume.
 
void except (std::exception_ptr exc)
 See PromiseCore::except.
 
- Public Member Functions inherited from uvco::RefCounted< PromiseCore< void > >
 RefCounted (const RefCounted &other)=default
 
 RefCounted (RefCounted &&other) noexcept
 
RefCountedoperator= (const RefCounted &other)=default
 
RefCountedoperator= (RefCounted &&other) noexcept
 
virtual ~RefCounted ()=default
 
virtual PromiseCore< void > * addRef ()
 
virtual void delRef ()
 

Public Attributes

bool ready_ = false
 
std::optional< std::exception_ptr > exception_
 Contains the exception if thrown.
 

Private Attributes

std::optional< std::coroutine_handle<> > handle_
 
PromiseState state_ = PromiseState::init
 

Additional Inherited Members

- Protected Member Functions inherited from uvco::RefCounted< PromiseCore< void > >
 RefCounted ()=default
 

Detailed Description

A void PromiseCore works like a normal PromiseCore, but with the specialization of not transferring values - only control is switched from the yielding to the awaiting coroutine.

Constructor & Destructor Documentation

◆ PromiseCore() [1/3]

uvco::PromiseCore< void >::PromiseCore ( )
default

◆ PromiseCore() [2/3]

uvco::PromiseCore< void >::PromiseCore ( const PromiseCore< void > &  )
delete

◆ PromiseCore() [3/3]

uvco::PromiseCore< void >::PromiseCore ( PromiseCore< void > &&  )
delete

◆ ~PromiseCore()

uvco::PromiseCore< void >::~PromiseCore ( )
override
45 {
46 BOOST_ASSERT(state_ != PromiseState::resuming);
48 fmt::print(stderr, "void Promise not finished\n");
49 }
50 if (handle_) {
51 fmt::print(stderr, "resumable coroutine destroyed\n");
52 handle_->destroy();
53 }
54}
PromiseState state_
Definition promise_core.h:233
std::optional< std::coroutine_handle<> > handle_
Definition promise_core.h:232

Member Function Documentation

◆ cancel()

void uvco::PromiseCore< void >::cancel ( )

See PromiseCore::cancel.

63 {
65 BOOST_ASSERT(!exception_);
66 if (!exception_) {
67 exception_ = std::make_exception_ptr(
68 UvcoException(UV_ECANCELED, "Promise cancelled"));
69 }
70 resume();
71 }
72}
std::optional< std::exception_ptr > exception_
Contains the exception if thrown.
Definition promise_core.h:229
void resume()
See PromiseCore::resume.
Definition promise_core.cc:32

◆ except()

void uvco::PromiseCore< void >::except ( std::exception_ptr  exc)

See PromiseCore::except.

56 {
57 BOOST_ASSERT(state_ == PromiseState::init ||
59 exception_ = std::move(exc);
60 ready_ = true;
61}
bool ready_
Definition promise_core.h:226

◆ operator=() [1/2]

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

◆ operator=() [2/2]

PromiseCore< void > & uvco::PromiseCore< void >::operator= ( PromiseCore< void > &&  )
delete

◆ ready()

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

See PromiseCore::ready.

27{ return exception_ || ready_; }

◆ resetHandle()

void uvco::PromiseCore< void >::resetHandle ( )

◆ resume()

void uvco::PromiseCore< void >::resume ( )

See PromiseCore::resume.

32 {
33 if (handle_) {
34 BOOST_ASSERT(state_ == PromiseState::waitedOn);
36 auto resumeHandle = *handle_;
37 handle_.reset();
38 Loop::enqueue(resumeHandle);
39 } else {
40 // If a coroutine returned immediately, or nobody is co_awaiting the result.
41 }
43}
static void enqueue(std::coroutine_handle<> handle)
Definition loop.cc:73

◆ setHandle()

void uvco::PromiseCore< void >::setHandle ( std::coroutine_handle<>  handle)

See PromiseCore::set_resume.

17 {
19 throw UvcoException("PromiseCore is already awaited or has finished");
20 }
21 BOOST_ASSERT(state_ == PromiseState::init);
22 handle_ = handle;
24}

◆ stale()

bool uvco::PromiseCore< void >::stale ( ) const

See PromiseCore::stale.

28 {
29 return state_ == PromiseState::finished && !ready();
30}
bool ready() const
See PromiseCore::ready.
Definition promise_core.cc:27

◆ willResume()

bool uvco::PromiseCore< void >::willResume ( ) const

See PromiseCore::willResume.

26{ return handle_.has_value(); }

Member Data Documentation

◆ exception_

std::optional<std::exception_ptr> uvco::PromiseCore< void >::exception_

Contains the exception if thrown.

◆ handle_

std::optional<std::coroutine_handle<> > uvco::PromiseCore< void >::handle_
private

◆ ready_

bool uvco::PromiseCore< void >::ready_ = false

In a void promise, we only track if the coroutine has finished, because it doesn't return anything.

◆ state_


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