#include <goal.hh>
Classes | |
struct | final_awaiter |
Public Member Functions | |
Co | get_return_object () |
InitialSuspend | initial_suspend () |
final_awaiter | final_suspend () noexcept |
void | return_value (Return) |
void | return_value (Done) |
void | return_value (Co &&) |
void | unhandled_exception () |
Co && | await_transform (Co &&co) |
std::suspend_always | await_transform (Suspend) |
Public Attributes | |
std::optional< Co > | continuation |
Goal * | goal = nullptr |
bool | alive = true |
Promise type for coroutines defined using Co. Attached to coroutine handle.
|
inline |
Allows awaiting a Suspend. Always suspends.
|
inlinenoexcept |
Called on co_return
. Creates final_awaiter which either jumps to continuation or suspends goal.
Co nix::promise_type::get_return_object | ( | ) |
|
inline |
void nix::promise_type::return_value | ( | Co && | next | ) |
When "returning" another coroutine, what happens is that we set it as our own continuation, thus once the final suspend happens, we transfer control to it. The original continuation we had is set as the continuation of the coroutine passed in. final_suspend is called after this, and final_awaiter will pass control off to continuation.
If we already have a continuation, that continuation is set as the continuation of the new continuation. Thus, the continuation passed to return_value must not have a continuation set.
|
inline |
Does nothing, but provides an opportunity for final_suspend to happen.
|
inline |
Does nothing, but provides an opportunity for final_suspend to happen.
|
inline |
If an exception is thrown inside a coroutine, we re-throw it in the context of the "resumer" of the continuation.
bool nix::Goal::promise_type::alive = true |
Is set to false when destructed to ensure we don't use a destructed coroutine by accident
std::optional<Co> nix::Goal::promise_type::continuation |
Either this is who called us, or it is who we will tail-call. It is what we "jump" to once we are done.
Goal* nix::Goal::promise_type::goal = nullptr |
The goal that we're a part of. Set either in Co::await_suspend or in constructor of Goal.