Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
nix::Goal::promise_type Struct Reference

#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< Cocontinuation
 
Goalgoal = nullptr
 
bool alive = true
 

Detailed Description

Promise type for coroutines defined using Co. Attached to coroutine handle.

Member Function Documentation

◆ await_transform() [1/2]

Co && nix::Goal::promise_type::await_transform ( Co && co)
inline

Allows awaiting a Co.

◆ await_transform() [2/2]

std::suspend_always nix::Goal::promise_type::await_transform ( Suspend )
inline

Allows awaiting a Suspend. Always suspends.

◆ final_suspend()

final_awaiter nix::Goal::promise_type::final_suspend ( )
inlinenoexcept

Called on co_return. Creates final_awaiter which either jumps to continuation or suspends goal.

◆ get_return_object()

Co nix::promise_type::get_return_object ( )

Called by compiler generated code to construct the Co that is returned from a Co-returning coroutine.

◆ initial_suspend()

InitialSuspend nix::Goal::promise_type::initial_suspend ( )
inline

Called by compiler generated code before body of coroutine. We use this opportunity to set the goal field and top_co field of Goal.

◆ return_value() [1/3]

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.

◆ return_value() [2/3]

void nix::Goal::promise_type::return_value ( Done )
inline

Does nothing, but provides an opportunity for final_suspend to happen.

◆ return_value() [3/3]

void nix::Goal::promise_type::return_value ( Return )
inline

Does nothing, but provides an opportunity for final_suspend to happen.

◆ unhandled_exception()

void nix::Goal::promise_type::unhandled_exception ( )
inline

If an exception is thrown inside a coroutine, we re-throw it in the context of the "resumer" of the continuation.

Member Data Documentation

◆ alive

bool nix::Goal::promise_type::alive = true

Is set to false when destructed to ensure we don't use a destructed coroutine by accident

◆ continuation

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

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.


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