Skip to documentation
SLOP

tiny.mprompt.SuspendedPrompt

Reference tiny.mprompt SuspendedPrompt

Defined in zig_api.

Returns the typed handle type for a body that paused inside a SuspendedRun.

Called byCallszig_apiPromptOutcometest sourcelib.mprompt.src.apitest: scheduler-style async prompts r...zig_apiPromptOutcomeprivate sourcelib.mprompt.src.apiSlotprivate sourcelib.mprompt.src.apioutcomeFromRawprivate sourcelib.mprompt.src.apislotPtrprivate sourcelib.mprompt.src.apiwriteSlotzig_apiSuspendedPrompt
Static calls · unresolved targets: 0 · external targets: 6.

Source

Source: lib/mprompt/src/api.zig:75

zig
/// Returns the typed handle type for a body that paused inside a `SuspendedRun`. A caller keeps/// this handle from the moment a run pauses until it continues or abandons the run, for example a/// scheduler that holds one handle per waiting worker. The handle points into the `SuspendedRun`/// that started the body, so that `SuspendedRun` must stay at the same address while the handle is/// in use. A one-shot handle is continued once or dropped once, because continuing it again, or/// after a drop, uses a stacklet the runtime has already freed or reused. `asMulti` turns it into a/// multi-shot handle that the caller can continue once per reference.pub fn SuspendedPrompt(comptime ResumeValue: type, comptime Result: type) type {    return struct {        /// Holds the runtime's resumption for the paused body. The methods pass it to the runtime's        /// `resumePrompt`, `resumeDrop`, `resumeMulti`, `resumeDup` and `resumeResumeCount`.        raw_resume: *raw.Resume,        /// Points to the done marker inside the `SuspendedRun` that started the body.        /// `continueWith` compares the runtime's result with this address to tell a finished body        /// from a new pause.        done_marker: *u8,        /// Points to the storage inside the `SuspendedRun` where the body's wrapper writes the        /// body's result. `continueWith` reads the result from it when the body finishes.        result: *Slot(Result),        const Self = @This();        /// Names the `PromptOutcome` type for this handle's `ResumeValue` and `Result`, which        /// `continueWith` returns.        pub const Outcome: type = PromptOutcome(ResumeValue, Result);        /// Resumes the paused body so that its `suspendPrompt` call returns `value`, for a caller        /// continuing the body with the value the pause is waiting for. The call runs the body on        /// its stacklet until it finishes or pauses again. The call returns `.returned` with the        /// body's result when the body finished, or `.suspended` with a new handle when it paused        /// again. The call uses up a one-shot handle, and a later pause comes back as a new handle        /// in `.suspended`. The call gives up one reference of a multi-shot handle. When other        /// references of a multi-shot handle 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) Outcome {            var slot: Slot(ResumeValue) = .{};            writeSlot(ResumeValue, &slot, value);            const raw_result = raw.resumePrompt(self.raw_resume, slotPtr(ResumeValue, &slot));            return outcomeFromRaw(ResumeValue, Result, raw_result, self.done_marker, self.result);        }        /// Continues the paused body with no value, for a `ResumeValue` of `void`. Any other        /// `ResumeValue` is a compile error.        pub fn continueWithoutValue(self: Self) Outcome {            if (ResumeValue != void) {                @compileError("continueWithoutValue requires ResumeValue to be void");            }            return self.continueWith({});        }        /// Returns a multi-shot handle for the same pause, for a caller that converts the handle        /// before continuing the same pause more than once. The caller uses the returned handle in        /// place of the old one. Converting a one-shot handle allocates a record from the process        /// allocator, and the record starts with one reference. The program stops with a panic if        /// that allocation fails. A handle that is already multi-shot comes back unchanged.        pub fn asMulti(self: Self) Self {            return .{                .raw_resume = raw.resumeMulti(self.raw_resume),                .done_marker = self.done_marker,                .result = self.result,            };        }        /// A caller takes one extra reference for each extra time it will continue the pause. The        /// call returns a second handle for the same pause and adds one reference, or returns null        /// for a one-shot handle. The call copies no stack memory. The runtime copies the paused        /// stack only when a resume finds other references still held.        pub fn dup(self: Self) ?Self {            const duplicated = raw.resumeDup(self.raw_resume) orelse return null;            return .{                .raw_resume = duplicated,                .done_marker = self.done_marker,                .result = self.result,            };        }        /// Gives up this handle without continuing the body, for a caller abandoning a paused body        /// it will never continue, as the Chic host does when it tears down a turn. For a one-shot        /// handle, and for the last reference of a multi-shot handle, the runtime frees the paused        /// stacklets, and the rest of the body never runs, so its `defer` statements never run        /// either.        pub fn drop(self: Self) void {            raw.resumeDrop(self.raw_resume);        }        /// Returns the number of resumes of a multi-shot handle, or 0 for a one-shot handle, for a        /// caller reading how many times the pause has been continued so far.        pub fn resumeCount(self: Self) c_long {            return raw.resumeResumeCount(self.raw_resume);        }    };}

Source: lib/mprompt/src/root.zig:60

zig
pub const SuspendedPrompt = zig_api.SuspendedPrompt;

Audit

Definitions1
Public names2
Members0
Version26.7.0
Revisiondaab053ee433