Nugget
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
psyqo::Coroutine< T > Struct Template Reference

A suitable type to hold and return a C++20 coroutine. More...

#include <psyqo/coroutine.hh>

Classes

struct  Awaiter
 The awaiter type. More...
 
struct  Empty
 

Public Types

typedef std::conditional< std::is_void< T >::value, Empty, T >::type SafeT
 
using promise_type = Promise
 

Public Member Functions

 Coroutine ()=default
 
 Coroutine (Coroutine &&other)=default
 
Coroutineoperator= (Coroutine &&other)=default
 
 Coroutine (Coroutine const &)=delete
 
Coroutineoperator= (Coroutine const &)=delete
 
Awaiter awaiter ()
 Creates an Awaiter object.
 
void resume ()
 Resumes the coroutine.
 
bool done ()
 Returns the status of the coroutine.
 
const SafeTvalue () const
 Returns the value returned by the coroutine.
 
constexpr bool await_ready ()
 
template<typename U >
constexpr void await_suspend (std::coroutine_handle< U > h)
 
constexpr SafeT await_resume ()
 

Detailed Description

template<typename T = void>
struct psyqo::Coroutine< T >

A suitable type to hold and return a C++20 coroutine.

C++20 introduced the concept of coroutines in the language. This type can be used to properly hold a coroutine and yield and resume it within psyqo. An important caveat of using coroutines is that the language insist on calling new and delete silently within the coroutine object. This may be a problem for users who don't want to use the heap.

Template Parameters
TThe type the coroutine returns. void by default.

Member Typedef Documentation

◆ promise_type

template<typename T = void>
using psyqo::Coroutine< T >::promise_type = Promise

◆ SafeT

template<typename T = void>
typedef std::conditional<std::is_void<T>::value,Empty,T>::type psyqo::Coroutine< T >::SafeT

Constructor & Destructor Documentation

◆ Coroutine() [1/3]

template<typename T = void>
psyqo::Coroutine< T >::Coroutine ( )
default

◆ Coroutine() [2/3]

template<typename T = void>
psyqo::Coroutine< T >::Coroutine ( Coroutine< T > &&  other)
default

◆ Coroutine() [3/3]

template<typename T = void>
psyqo::Coroutine< T >::Coroutine ( Coroutine< T > const &  )
delete

Member Function Documentation

◆ await_ready()

template<typename T = void>
constexpr bool psyqo::Coroutine< T >::await_ready ( )
inlineconstexpr

◆ await_resume()

template<typename T = void>
constexpr SafeT psyqo::Coroutine< T >::await_resume ( )
inlineconstexpr

◆ await_suspend()

template<typename T = void>
template<typename U >
constexpr void psyqo::Coroutine< T >::await_suspend ( std::coroutine_handle< U >  h)
inlineconstexpr

◆ awaiter()

template<typename T = void>
Awaiter psyqo::Coroutine< T >::awaiter ( )
inline

Creates an Awaiter object.

This method is used to create an instance of the Awaiter object. It's used to suspend the coroutine after scheduling an asynchronous operation.

◆ done()

template<typename T = void>
bool psyqo::Coroutine< T >::done ( )
inline

Returns the status of the coroutine.

This method returns the status of the coroutine. It will return true if the coroutine is done executing, false otherwise. The typical usage of this method is to poll it from the scene loop. The first time it returns true, the coroutine will be destroyed. The next times, it will return true without doing anything, making the polling loop faster.

◆ operator=() [1/2]

template<typename T = void>
Coroutine & psyqo::Coroutine< T >::operator= ( Coroutine< T > &&  other)
default

◆ operator=() [2/2]

template<typename T = void>
Coroutine & psyqo::Coroutine< T >::operator= ( Coroutine< T > const &  )
delete

◆ resume()

template<typename T = void>
void psyqo::Coroutine< T >::resume ( )
inline

Resumes the coroutine.

This method resumes the coroutine. It's used to resume the coroutine after an asynchronous operation has completed. It is safe to call it from within the coroutine itself, meaning it is safe to call it from a callback which may execute in the same callstack as the coroutine. In this case, the next co_yield on the Awaiter object will be a no-op.

◆ value()

template<typename T = void>
const SafeT & psyqo::Coroutine< T >::value ( ) const
inline

Returns the value returned by the coroutine.

This method returns the value returned by the coroutine. It is only valid to call it after the coroutine has finished executing. The typical usage of this method is to call it after the done method returns true. The coroutine sets its return value using the co_return keyword. Since it is possible for the return type to be void, the return type of this method is T if T is not void, and Empty if T is void.


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