Nugget
|
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 | |
Coroutine & | operator= (Coroutine &&other)=default |
Coroutine (Coroutine const &)=delete | |
Coroutine & | operator= (Coroutine const &)=delete |
Awaiter | awaiter () |
Creates an Awaiter object. | |
void | resume () |
Resumes the coroutine. | |
bool | done () |
Returns the status of the coroutine. | |
const SafeT & | value () 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 () |
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.
T | The type the coroutine returns. void by default. |
using psyqo::Coroutine< T >::promise_type = Promise |
typedef std::conditional<std::is_void<T>::value,Empty,T>::type psyqo::Coroutine< T >::SafeT |
|
default |
|
default |
|
delete |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inline |
|
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.
|
default |
|
delete |
|
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.
|
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
.