tiny.mprompt.EffectContinuation
Defined in effect.
Returns the continuation type for clause kinds scoped_once, scoped, once and multi, so a typed clause that may keep the body waiting receives one and resumes the body with the operation's result.
Source
Source: lib/mprompt/src/effect.zig:479
zig
/// Returns the continuation type for clause kinds `scoped_once`, `scoped`, `once` and `multi`, so a/// typed clause that may keep the body waiting receives one and resumes the body with the/// operation's result. Any other kind is a compile error. `ResumeValue` is the operation's result/// type, which `perform` returns in the body. `HandlerResult` is the result type of the `handle`/// call. A resume returns when the resumed body finishes, with the body's result, or when a later/// clause suspends the body and returns, with that clause's result. A `scoped_once` or `once`/// continuation is resumed at most once, and a `scoped` or `multi` continuation is resumed any/// number of times, with its last resume final. A `scoped`, `once` or `multi` continuation that/// gets no final resume and no release stays allocated.pub fn EffectContinuation(comptime ResumeValue: type, comptime HandlerResult: type, comptime kind: OperationKind) type { comptime { switch (kind) { .scoped_once, .scoped, .once, .multi => {}, else => @compileError("effect continuations are only available for scoped_once, scoped, once, and multi operations"), } } return struct { /// The raw resumption for the suspended body. raw_resume: *Resume, /// The handler's local state, passed back with each resume. The typed `handle` sets it to /// the address of its own environment, which holds the context and the result. local: ?*anyopaque, const Self = @This(); /// Resumes the body with `value` as the result of its `perform` and returns the handler's /// result, for every resume but the last in a clause that resumes the body more than once, /// as a search over both branches of a choice does. A `scoped` or `multi` continuation /// stays usable for another resume. This call is the one resume for a `scoped_once` /// continuation. A `once` continuation is a compile error here, and it uses /// `continueFinalWith` or `continueTailWith`. pub fn continueWith(self: Self, value: ResumeValue) HandlerResult { if (kind == .once) { @compileError("once continuations must use continueFinalWith or continueTailWith"); } return self.continueInternal(.regular, value); } /// Resumes the body with `value` as the result of its `perform` and returns the handler's /// result, so a clause makes its last resume of the body. This call is the continuation's /// last resume: it frees an allocated continuation, which no caller uses again. pub fn continueFinalWith(self: Self, value: ResumeValue) HandlerResult { return self.continueInternal(.final, value); } /// Resumes the body with `value` as a tail resume and frees an allocated continuation, for /// a clause whose last act is to resume the body, so no clause frame stays under the /// resumed body. For every kind this type allows, control does not come back to the clause, /// and the result goes to the call that entered or last resumed the handled body. The call /// must be the clause's last action. pub fn continueTailWith(self: Self, value: ResumeValue) HandlerResult { return self.continueInternal(.tail, value); } /// Resumes the body with no value, for a `ResumeValue` of `void`. Any other `ResumeValue` /// is a compile error. pub fn continueWithoutValue(self: Self) HandlerResult { if (ResumeValue != void) { @compileError("continueWithoutValue requires ResumeValue to be void"); } return self.continueWith({}); } /// Makes the final resume with no value, for a `ResumeValue` of `void`. Any other /// `ResumeValue` is a compile error. pub fn continueFinalWithoutValue(self: Self) HandlerResult { if (ResumeValue != void) { @compileError("continueFinalWithoutValue requires ResumeValue to be void"); } return self.continueFinalWith({}); } /// Makes a tail resume with no value, for a `ResumeValue` of `void`. Any other /// `ResumeValue` is a compile error. pub fn continueTailWithoutValue(self: Self) HandlerResult { if (ResumeValue != void) { @compileError("continueTailWithoutValue requires ResumeValue to be void"); } return self.continueTailWith({}); } /// Ends the suspended body without running its rest, for a clause that will not continue /// the body, such as a failing branch of a search. The body is resumed only to jump back to /// its handler, and its stacklet is freed. For a `multi` or `scoped` continuation that /// other references share, or that has resumed before, the call gives up one reference and /// resumes nothing. The call is valid for `scoped`, `once` and `multi` continuations, and /// any other kind is a compile error. A `finally` call inside the ended body never calls /// its `finally_fun` function. pub fn release(self: Self) void { switch (kind) { .scoped, .once, .multi => {}, else => @compileError("release is only valid for scoped, once, and multi continuations"), } resumeRelease(self.raw_resume); } fn continueInternal(self: Self, comptime continue_kind: ContinueKind, value: ResumeValue) HandlerResult { var slot: Slot(ResumeValue) = .{}; writeSlot(ResumeValue, &slot, value); const result = switch (continue_kind) { .regular => resumeEffect(self.raw_resume, self.local, slotPtr(ResumeValue, &slot)), .final => resumeFinal(self.raw_resume, self.local, slotPtr(ResumeValue, &slot)), .tail => resumeTail(self.raw_resume, self.local, slotPtr(ResumeValue, &slot)), }; return readSlot(HandlerResult, result); } };}Source: lib/mprompt/src/root.zig:62
zig
pub const EffectContinuation = effect.EffectContinuation;Complete call list
8 direct calls.
lib.mprompt.src.effect.Slot[function] — private source atlib/mprompt/src/effect.zig:610in nearest public ownertiny.mprompt.effectlib.mprompt.src.effect.readSlot[function] — private source atlib/mprompt/src/effect.zig:636in nearest public ownertiny.mprompt.effecttiny.mprompt.effect.resumeEffect[function] atlib/mprompt/src/effect.zig:879tiny.mprompt.effect.resumeFinal[function] atlib/mprompt/src/effect.zig:887tiny.mprompt.effect.resumeRelease[function] atlib/mprompt/src/effect.zig:928tiny.mprompt.effect.resumeTail[function] atlib/mprompt/src/effect.zig:897lib.mprompt.src.effect.slotPtr[function] — private source atlib/mprompt/src/effect.zig:629in nearest public ownertiny.mprompt.effectlib.mprompt.src.effect.writeSlot[function] — private source atlib/mprompt/src/effect.zig:616in nearest public ownertiny.mprompt.effect
Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |