uvco 0.1
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Types | List of all members
uvco::Coroutine< T > Class Template Reference

A coroutine object used internally by C++20 coroutines ("promise object"). More...

#include <promise.h>

Collaboration diagram for uvco::Coroutine< T >:
Collaboration graph
[legend]

Public Member Functions

 Coroutine ()
 
 Coroutine (const Coroutine &other)=delete
 
Coroutineoperator= (const Coroutine &other)=delete
 
 Coroutine (Coroutine &&other)=delete
 
Coroutineoperator= (Coroutine &&other)=delete
 
 ~Coroutine ()
 
Promise< T > get_return_object ()
 
void return_value (T value)
 
std::suspend_never initial_suspend () noexcept
 
std::suspend_never final_suspend () noexcept
 
void unhandled_exception ()
 

Protected Attributes

SharedCore_ core_
 

Private Types

using PromiseCore_ = PromiseCore<T>
 PromiseCore_ handles the inner mechanics of resumption and suspension.
 
using SharedCore_ = PromiseCore_ *
 

Detailed Description

template<typename T>
class uvco::Coroutine< T >

A coroutine object used internally by C++20 coroutines ("promise object").

Member Typedef Documentation

◆ PromiseCore_

template<typename T >
using uvco::Coroutine< T >::PromiseCore_ = PromiseCore<T>
private

PromiseCore_ handles the inner mechanics of resumption and suspension.

◆ SharedCore_

template<typename T >
using uvco::Coroutine< T >::SharedCore_ = PromiseCore_ *
private

Constructor & Destructor Documentation

◆ Coroutine() [1/3]

template<typename T >
uvco::Coroutine< T >::Coroutine ( )
inline

Coroutine object lives and is pinned within the coroutine frame; copy/move is disallowed.

295: core_{makeRefCounted<PromiseCore_>()} {}
SharedCore_ core_
Definition promise.h:345

◆ Coroutine() [2/3]

template<typename T >
uvco::Coroutine< T >::Coroutine ( const Coroutine< T > &  other)
delete

◆ Coroutine() [3/3]

template<typename T >
uvco::Coroutine< T >::Coroutine ( Coroutine< T > &&  other)
delete

◆ ~Coroutine()

template<typename T >
uvco::Coroutine< T >::~Coroutine ( )
inline
301 {
302 if (core_ != nullptr) {
303 core_->delRef();
304 }
305 }
virtual void delRef()
Definition internal_utils.h:117

Member Function Documentation

◆ final_suspend()

template<typename T >
std::suspend_never uvco::Coroutine< T >::final_suspend ( )
inlinenoexcept

Part of the coroutine protocol: called upon co_return or unhandled exception.

335{ return {}; }

◆ get_return_object()

template<typename T >
Promise< T > uvco::Coroutine< T >::get_return_object ( )
inline

Part of the coroutine protocol: Called on first suspension point (co_await) or co_return.

309{ return Promise<T>{core_}; }

◆ initial_suspend()

template<typename T >
std::suspend_never uvco::Coroutine< T >::initial_suspend ( )
inlinenoexcept

Part of the coroutine protocol: called after construction of Promise object, i.e. before starting the coroutine.

In uvco, the coroutine always runs at least up to its first suspension point, at which point it may be suspended (if the awaited object is not ready).

332{ return {}; }

◆ operator=() [1/2]

template<typename T >
Coroutine & uvco::Coroutine< T >::operator= ( const Coroutine< T > &  other)
delete

◆ operator=() [2/2]

template<typename T >
Coroutine & uvco::Coroutine< T >::operator= ( Coroutine< T > &&  other)
delete

◆ return_value()

template<typename T >
void uvco::Coroutine< T >::return_value ( value)
inline

Part of the coroutine protocol: Called by co_return. Schedules the awaiting coroutine for resumption.

313 {
314 // Probably cancelled.
315 if (core_->slot.has_value() && core_->slot->index() == 1) {
316 return;
317 }
318 BOOST_ASSERT(!core_->slot);
319 core_->slot = std::move(value);
320 core_->resume();
321 }
std::optional< std::variant< T, std::exception_ptr > > slot
The slot contains the result once obtained.
Definition promise_core.h:184
virtual void resume()
Definition promise_core.h:126

◆ unhandled_exception()

template<typename T >
void uvco::Coroutine< T >::unhandled_exception ( )
inline
339 {
340 core_->except(std::current_exception());
341 core_->resume();
342 }
void except(const std::exception_ptr &exc)
Definition promise_core.h:181

Member Data Documentation

◆ core_

template<typename T >
SharedCore_ uvco::Coroutine< T >::core_
protected

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