tiny.mprompt.Continuation
Defined in zig_api.
Returns the typed handle type that a yieldWith handler gets for the paused rest of the body, for a handler that uses it to continue the paused body with its answer.
Source
Source: lib/mprompt/src/api.zig:257
zig
/// Returns the typed handle type that a `yieldWith` handler gets for the paused rest of the body,/// for a handler that uses it to continue the paused body with its answer. `ResumeValue` is the/// type the paused `yieldWith` call returns. `PromptResult` is the type the body's `run` returns./// `PromptResult` must be the `Result` of the enclosing `run`, and the compiler does not check that/// the two match. The handler must call one of the continue methods before it returns, or the/// program stops with a panic.pub fn Continuation(comptime ResumeValue: type, comptime PromptResult: type) type { return struct { /// Holds the runtime's resumption for the paused body. raw_resume: *raw.Resume, /// Points to a flag in `yieldWith` that a continue method sets once the body hands control /// back. `yieldWith` stops the program with a panic when the handler returns and the flag /// is still false. continued: *bool, /// Points to where a continue method stores the runtime's result pointer. `yieldWith` /// returns that pointer to the call that entered the prompt. raw_result: *?*anyopaque, const Self = @This(); /// Resumes the paused body so that its `yieldWith` call returns `value`, for a handler /// continuing the paused body with its answer and getting the body's result back. The call /// returns the body's result once the body runs to its end, through any later pauses that /// their own handlers continue. The call marks the continuation as used. A one-shot /// continuation is continued once. When other references of a multi-shot continuation /// remain, the call first copies the paused stack to the heap, and a later resume copies it /// back. pub fn continueWith(self: Self, value: ResumeValue) PromptResult { return self.continueInternal(false, value); } /// Resumes the paused body with `value` as a tail resume, for a handler whose last act is /// to continue the body, so repeated pauses do not pile up handler frames. For a one-shot /// continuation, control never comes back to the handler, and the body's result goes /// straight to the call that entered the prompt. The call must be the handler's last /// action. For a multi-shot continuation, only the first tail resume works this way, and /// later ones behave as `continueWith` does. pub fn continueTailWith(self: Self, value: ResumeValue) PromptResult { return self.continueInternal(true, value); } /// Continues the paused body with no value, for a `ResumeValue` of `void`. Any other /// `ResumeValue` is a compile error. pub fn continueWithoutValue(self: Self) PromptResult { if (ResumeValue != void) { @compileError("continueWithoutValue requires ResumeValue to be void"); } return self.continueWith({}); } /// Continues the paused body with no value as a tail resume, for a `ResumeValue` of `void`. /// Any other `ResumeValue` is a compile error. pub fn continueTailWithoutValue(self: Self) PromptResult { if (ResumeValue != void) { @compileError("continueTailWithoutValue requires ResumeValue to be void"); } return self.continueTailWith({}); } /// Returns a multi-shot continuation for the same pause, for a handler that converts the /// continuation before continuing the same pause more than once, as a search that tries /// each branch does. The handler uses the returned continuation in place of the old one. /// Converting a one-shot continuation allocates a record from the process allocator, and /// the program stops with a panic if that allocation fails. A continuation that is already /// multi-shot comes back unchanged. Each continue call gives up one reference, so /// continuing twice takes a `dup` first. pub fn asMulti(self: Self) Self { return .{ .raw_resume = raw.resumeMulti(self.raw_resume), .continued = self.continued, .raw_result = self.raw_result, }; } /// A handler takes one extra reference for each extra time it will continue the pause. The /// call returns a second continuation for the same pause and adds one reference, or returns /// null for a one-shot continuation. The call copies no stack memory. pub fn dup(self: Self) ?Self { const duplicated = raw.resumeDup(self.raw_resume) orelse return null; return .{ .raw_resume = duplicated, .continued = self.continued, .raw_result = self.raw_result, }; } /// Gives up one reference without continuing the body, for a handler giving back an extra /// reference it took and will not use. The handler must still continue the body through /// another reference before it returns, because a handler that drops its only reference and /// returns stops the program with a panic. pub fn drop(self: Self) void { raw.resumeDrop(self.raw_resume); } /// Returns the number of resumes of a multi-shot continuation, or 0 for a one-shot /// continuation, for a handler reading how many times the pause has been continued so far. pub fn resumeCount(self: Self) c_long { return raw.resumeResumeCount(self.raw_resume); } fn continueInternal(self: Self, comptime tail: bool, value: ResumeValue) PromptResult { var slot: Slot(ResumeValue) = .{}; writeSlot(ResumeValue, &slot, value); const result = if (tail) raw.resumeTailPrompt(self.raw_resume, slotPtr(ResumeValue, &slot)) else raw.resumePrompt(self.raw_resume, slotPtr(ResumeValue, &slot)); self.continued.* = true; self.raw_result.* = result; return readSlot(PromptResult, result); } };}Source: lib/mprompt/src/root.zig:58
zig
pub const Continuation = zig_api.Continuation;Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |