tvix_eval::vm::generators

Type Alias Generator

Source
pub(crate) type Generator = Gen<VMRequest, VMResponse, Pin<Box<dyn Future<Output = Result<Value, ErrorKind>>>>>;

Aliased Type§

struct Generator { /* private fields */ }

Implementations

Source§

impl<Y, R, F> Gen<Y, R, F>
where F: Future,

Source

pub fn new(producer: impl FnOnce(Co<Airlock<Y, R>>) -> F) -> Gen<Y, R, F>

Creates a new generator from a function.

The function accepts a Co object, and returns a future. Every time the generator is resumed, the future is polled. Each time the future is polled, it should do one of two things:

  • Call co.yield_(), and then return Poll::Pending.
  • Drop the Co, and then return Poll::Ready.

Typically this exchange will happen in the context of an async fn.

See the module-level docs for examples.

Source

pub fn resume_with( &mut self, arg: R, ) -> GeneratorState<Y, <F as Future>::Output>

Resumes execution of the generator.

arg is the resume argument. If the generator was previously paused by awaiting a future returned from co.yield(), that future will complete, and return arg.

If the generator yields a value, Yielded is returned. Otherwise, Completed is returned.

See the module-level docs for examples.

Trait Implementations

Source§

impl<Y, R, F> Coroutine for Gen<Y, R, F>
where F: Future,

Source§

type Yield = Y

The type of value this generator yields.
Source§

type Resume = R

The type of value this generator accepts as a resume argument.
Source§

type Return = <F as Future>::Output

The type of value this generator returns upon completion.
Source§

fn resume_with( self: Pin<&mut Gen<Y, R, F>>, arg: R, ) -> GeneratorState<<Gen<Y, R, F> as Coroutine>::Yield, <Gen<Y, R, F> as Coroutine>::Return>

Resumes the execution of this generator. Read more