fiber
Loading...
Searching...
No Matches
fiber::CoroutinePromise< ReturnType > Class Template Reference

Promise type for an fiber::Coroutine. More...

#include <Coroutine.hpp>

Inheritance diagram for fiber::CoroutinePromise< ReturnType >:
fiber::CoroutineNode

Public Member Functions

 CoroutinePromise ()
 
template<class Awaitable>
constexpr auto await_transform (Awaitable &&awaitable)
 
auto get_return_object ()
 
constexpr void unhandled_exception () noexcept
 Print an error message and kill the task.
 
constexpr void return_value (const ReturnType &value)
 
constexpr void return_value (ReturnType &&value)
 
constexpr ReturnType && get_return_value ()
 
constexpr bool await_ready () const noexcept
 
constexpr ReturnType await_resume ()
 
- Public Member Functions inherited from fiber::CoroutineNode
void destroy () noexcept
 
void resume () noexcept
 
bool is_done () const noexcept
 
constexpr operator bool ()
 
constexpr TaskBasetask ()
 
constexpr const TaskBasetask () const
 
constexpr CoroutineNodeparent ()
 
constexpr const CoroutineNodeparent () const
 
constexpr std::coroutine_handle handle ()
 
constexpr const std::coroutine_handle handle () const
 
constexpr void Register (TaskBase *task)
 
template<class ReturnType>
constexpr void await_suspend (std::coroutine_handle< CoroutinePromise< ReturnType > > handle) noexcept
 
bool await_ready () const noexcept
 
constexpr std::suspend_always final_suspend () noexcept
 
constexpr std::suspend_always initial_suspend () noexcept
 

Static Public Member Functions

static constexpr void * operator new (std::size_t size)
 
static constexpr void operator delete (void *ptr, std::size_t size)
 

Additional Inherited Members

- Public Attributes inherited from fiber::CoroutineNode
std::coroutine_handle _handle = nullptr
 
TaskBase_task = nullptr
 
CoroutineNode_parent = nullptr
 

Detailed Description

template<class ReturnType = void>
class fiber::CoroutinePromise< ReturnType >

Promise type for an fiber::Coroutine.

This class implements the coroutine promise required by the C++20 coroutine machinery. CoroutinePromise<ReturnType> is instantiated by the compiler when a coroutine with Coroutine<ReturnType> as its return type is used.

Awaitable Support

The await_transform() method is used to wrap arbitrary awaitables unless they already derive from a framework-specific AwaitableNode. This supports customization of how co_await expressions behave within the coroutine body.

Memory Management

Overrides operator new and operator delete to allocate memory for the coroutine frame from a custom allocator. In the usual cast this allocator is provided by the root task of the coroutine chain

See also
fiber::Coroutine
fiber::CoroutineNode
fiber::AwaitableWrapper

Constructor & Destructor Documentation

◆ CoroutinePromise()

template<class ReturnType = void>
fiber::CoroutinePromise< ReturnType >::CoroutinePromise ( )
inline

Member Function Documentation

◆ await_ready()

template<class ReturnType = void>
bool fiber::CoroutinePromise< ReturnType >::await_ready ( ) const
inlineconstexprnoexcept

◆ await_resume()

template<class ReturnType = void>
ReturnType fiber::CoroutinePromise< ReturnType >::await_resume ( )
inlineconstexpr

◆ await_transform()

template<class ReturnType = void>
template<class Awaitable>
auto fiber::CoroutinePromise< ReturnType >::await_transform ( Awaitable && awaitable)
inlineconstexpr

◆ get_return_object()

template<class ReturnType = void>
auto fiber::CoroutinePromise< ReturnType >::get_return_object ( )
inline

◆ get_return_value()

template<class ReturnType = void>
ReturnType && fiber::CoroutinePromise< ReturnType >::get_return_value ( )
inlineconstexpr

◆ operator delete()

template<class ReturnType = void>
static constexpr void fiber::CoroutinePromise< ReturnType >::operator delete ( void * ptr,
std::size_t size )
inlinestaticconstexpr

◆ operator new()

template<class ReturnType = void>
static constexpr void * fiber::CoroutinePromise< ReturnType >::operator new ( std::size_t size)
inlinestaticconstexpr

◆ return_value() [1/2]

template<class ReturnType = void>
void fiber::CoroutinePromise< ReturnType >::return_value ( const ReturnType & value)
inlineconstexpr

◆ return_value() [2/2]

template<class ReturnType = void>
void fiber::CoroutinePromise< ReturnType >::return_value ( ReturnType && value)
inlineconstexpr

◆ unhandled_exception()

template<class ReturnType = void>
void fiber::CoroutinePromise< ReturnType >::unhandled_exception ( )
inlineconstexprnoexcept

Print an error message and kill the task.


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