pub struct Yielder<'a, Effs>where
Effs: MapResume,{ /* private fields */ }Expand description
Handle passed to computation closures for yielding effects.
Use yield_ to perform an effect and receive the handler’s
resume value.
Implementations§
Source§impl<'a, Effs> Yielder<'a, Effs>where
Effs: MapResume,
impl<'a, Effs> Yielder<'a, Effs>where
Effs: MapResume,
Sourcepub async fn yield_<E, Index>(&self, effect: E) -> E::Resume<'a>where
E: Effect,
Effs: CoprodInjector<E, Index>,
<Effs as MapResume>::Output<'a>: CoprodUninjector<E::Resume<'a>, Index>,
pub async fn yield_<E, Index>(&self, effect: E) -> E::Resume<'a>where
E: Effect,
Effs: CoprodInjector<E, Index>,
<Effs as MapResume>::Output<'a>: CoprodUninjector<E::Resume<'a>, Index>,
Yield an effect to the handler and suspend until resumed.
Returns the resume value provided by the handler for this effect.
Sourcepub async fn invoke<'b, SubEffs, R, L, Indices>(
&self,
program: Effectful<'b, SubEffs, R, L>,
) -> Rwhere
SubEffs: Effects<'b> + EmbedEffect<Effs, Indices>,
<Effs as MapResume>::Output<'a>: ProjectResume<'a, SubEffs, Indices>,
L: Locality,
'a: 'b,
pub async fn invoke<'b, SubEffs, R, L, Indices>(
&self,
program: Effectful<'b, SubEffs, R, L>,
) -> Rwhere
SubEffs: Effects<'b> + EmbedEffect<Effs, Indices>,
<Effs as MapResume>::Output<'a>: ProjectResume<'a, SubEffs, Indices>,
L: Locality,
'a: 'b,
Invoke a sub-program, forwarding its effects through this yielder.
The sub-program’s effects must be a subset of this yielder’s effects. Each effect yielded by the sub-program is forwarded to the outer handler via this yielder, and the resume value is passed back to the sub-program.
Effect forwarding uses synchronous coproduct conversions
([EmbedEffect] / [ProjectResume]) combined with the raw generator
yield. This works in both Send and non-Send contexts.
Returns the sub-program’s result directly. If the outer handler cancels,
the entire coroutine is dropped, so invoke never returns in that case.
The sub-program may use a lifetime 'b shorter than the outer program’s 'a.
This allows sequential invocations that borrow from the same mutable reference,
since each invocation only borrows for its own duration rather than for the
entire outer computation lifetime.