CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::AsyncGenerator< T, Lockable > Class Template Referencefinal

A generator represents a coroutine type that produces a sequence of values of type T, where values are produced lazily and synchronously. More...

#include <CeresEngine/Foundation/Generator.hpp>

Classes

class  Iterator
 An iterator type that allows the caller to iterate over the results of a generator. More...
 
class  Promise
 

Public Types

using promise_type = Promise
 A type required by the coroutine implementation.
 

Public Member Functions

 AsyncGenerator () noexcept
 Creates a new empty generator.
 
 AsyncGenerator (const AsyncGenerator &)=delete
 Disables copy constructor.
 
AsyncGeneratoroperator= (const AsyncGenerator &)=delete
 Disables copy assignment operator.
 
 AsyncGenerator (AsyncGenerator &&other) noexcept
 Creates a new generator by moving the contents of another.
 
AsyncGeneratoroperator= (AsyncGenerator &&other) noexcept
 Assigns the generator by moving the contents of another.
 
 ~AsyncGenerator () noexcept
 
Iterator begin ()
 
Iterator end () noexcept
 

Private Types

using Reference = T &
 
using Pointer = T *
 
using CoroutineHandle = coroutine_handle< Promise >
 The coroutine handle type.
 
using AsyncCoroutineHandle = coroutine_handle<>
 The coroutine handle for an asynchronous task.
 
using suspend_always = CeresEngine::suspend_always
 An alias to std::suspend_always.
 
using suspend_never = CeresEngine::suspend_never
 An alias to std::suspend_never.
 

Private Member Functions

 AsyncGenerator (Promise *promise) noexcept
 Creates a new AsyncGenerator from an existing coroutine handle.
 

Private Attributes

CoroutineHandle mCoroutine
 

Detailed Description

template<typename T, typename Lockable = Mutex>
class CeresEngine::AsyncGenerator< T, Lockable >

A generator represents a coroutine type that produces a sequence of values of type T, where values are produced lazily and synchronously.

The coroutine body is able to yield values of type T using the co_yield keyword. Note, however, that the coroutine body is not able to use the co_await keyword; values must be produced synchronously.

When a coroutine function returning a Generator<T> is called the coroutine is created initially suspended. Execution of the coroutine enters the coroutine body when the Generator<T>::begin() method is called and continues until either the first co_yield statement is reached or the coroutine runs to completion.

If the returned iterator is not equal to the end() iterator then dereferencing the iterator will return a reference to the value passed to the co_yield statement.

Calling operator++() on the iterator will resume execution of the coroutine and continue until either the next co_yield point is reached or the coroutine runs to completion.

Any unhandled exceptions thrown by the coroutine will propagate out of the begin() or operator++() calls to the caller.

Template Parameters
Tthe value type returned by the generator.

Member Typedef Documentation

◆ AsyncCoroutineHandle

template<typename T , typename Lockable = Mutex>
using CeresEngine::AsyncGenerator< T, Lockable >::AsyncCoroutineHandle = coroutine_handle<>
private

The coroutine handle for an asynchronous task.

◆ CoroutineHandle

template<typename T , typename Lockable = Mutex>
using CeresEngine::AsyncGenerator< T, Lockable >::CoroutineHandle = coroutine_handle<Promise>
private

The coroutine handle type.

◆ Pointer

template<typename T , typename Lockable = Mutex>
using CeresEngine::AsyncGenerator< T, Lockable >::Pointer = T*
private

◆ promise_type

template<typename T , typename Lockable = Mutex>
using CeresEngine::AsyncGenerator< T, Lockable >::promise_type = Promise

A type required by the coroutine implementation.

◆ Reference

template<typename T , typename Lockable = Mutex>
using CeresEngine::AsyncGenerator< T, Lockable >::Reference = T&
private

◆ suspend_always

template<typename T , typename Lockable = Mutex>
using CeresEngine::AsyncGenerator< T, Lockable >::suspend_always = CeresEngine::suspend_always
private

An alias to std::suspend_always.

◆ suspend_never

template<typename T , typename Lockable = Mutex>
using CeresEngine::AsyncGenerator< T, Lockable >::suspend_never = CeresEngine::suspend_never
private

An alias to std::suspend_never.

Constructor & Destructor Documentation

◆ AsyncGenerator() [1/4]

template<typename T , typename Lockable = Mutex>
CeresEngine::AsyncGenerator< T, Lockable >::AsyncGenerator ( )
inlinenoexcept

Creates a new empty generator.

This generator will always return an empty set of elements.

◆ AsyncGenerator() [2/4]

template<typename T , typename Lockable = Mutex>
CeresEngine::AsyncGenerator< T, Lockable >::AsyncGenerator ( const AsyncGenerator< T, Lockable > &  )
delete

Disables copy constructor.

◆ AsyncGenerator() [3/4]

template<typename T , typename Lockable = Mutex>
CeresEngine::AsyncGenerator< T, Lockable >::AsyncGenerator ( AsyncGenerator< T, Lockable > &&  other)
inlinenoexcept

Creates a new generator by moving the contents of another.

Parameters
otherThe generator to move from.

◆ ~AsyncGenerator()

template<typename T , typename Lockable = Mutex>
CeresEngine::AsyncGenerator< T, Lockable >::~AsyncGenerator ( )
inlinenoexcept

◆ AsyncGenerator() [4/4]

template<typename T , typename Lockable = Mutex>
CeresEngine::AsyncGenerator< T, Lockable >::AsyncGenerator ( Promise promise)
inlineexplicitprivatenoexcept

Creates a new AsyncGenerator from an existing coroutine handle.

Parameters
promiseThe promise object to create the async generator from

Member Function Documentation

◆ begin()

template<typename T , typename Lockable = Mutex>
Iterator CeresEngine::AsyncGenerator< T, Lockable >::begin ( )
inline
Returns
An iterator that points to the first generated value

◆ end()

template<typename T , typename Lockable = Mutex>
Iterator CeresEngine::AsyncGenerator< T, Lockable >::end ( )
inlinenoexcept

◆ operator=() [1/2]

template<typename T , typename Lockable = Mutex>
AsyncGenerator & CeresEngine::AsyncGenerator< T, Lockable >::operator= ( AsyncGenerator< T, Lockable > &&  other)
inlinenoexcept

Assigns the generator by moving the contents of another.

Parameters
otherThe generator to move from.
Returns
The newly moved generator

◆ operator=() [2/2]

Disables copy assignment operator.

Member Data Documentation

◆ mCoroutine

template<typename T , typename Lockable = Mutex>
CoroutineHandle CeresEngine::AsyncGenerator< T, Lockable >::mCoroutine
private

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