Mercury Currency Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
mce::coroutine Struct Reference

#include <coroutine.hpp>

Inheritance diagram for mce::coroutine:
Inheritance graph
[legend]

Public Member Functions

template<typename THUNK >
 coroutine (THUNK &&th)
 construct a coroutine from a thunk
 
template<typename StackAllocator , typename THUNK >
 coroutine (StackAllocator &&sa, THUNK &&th)
 construct a coroutine from a stack allocator and thunk
 
 coroutine (const coroutine &source)=delete
 
 coroutine (coroutine &&rhs) noexcept
 Move Constructor.
 
coroutineoperator= (const coroutine &rhs)=delete
 
coroutineoperator= (coroutine &&rhs) noexcept
 Move Assignment.
 
virtual void run ()
 Execute until thunk completes or yield() is called. More...
 
void yield ()
 Pause execution and return to run() caller. More...
 
bool complete ()
 Returns true if thunk is complete, else false since the coroutine yielded early.
 

Static Public Member Functions

template<typename Callable , typename... As>
static std::unique_ptr< coroutinemake (Callable &&cb, As &&... as)
 construct an allocated coroutine from a Callable and arguments More...
 

Detailed Description

A coroutine object. Argument thunk can yield execution at any point using mce::yield(). make_thunk() from the thunk.hpp is helpful for making executable functions to pass to coroutine constructor.

Member Function Documentation

◆ make()

template<typename Callable , typename... As>
static std::unique_ptr<coroutine> mce::coroutine::make ( Callable &&  cb,
As &&...  as 
)
inlinestatic

construct an allocated coroutine from a Callable and arguments

Parameters
cba Callable
asarguments to pass to Callable
Returns
an allocated coroutine

◆ run()

virtual void mce::coroutine::run ( )
inlinevirtual

Execute until thunk completes or yield() is called.

Execute until thunk completes or yield() is called. If thunk is complete run() returns immediately.

This operation is virtual to allow for code injection at run() call.

Reimplemented in mce::detail::await_coroutine.

◆ yield()

void mce::coroutine::yield ( )
inline

Pause execution and return to run() caller.

Pause execution and return to run() caller. Should only be called from within the associated coroutine while said coroutine is running.


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