Skuld.Comp.ISentinel protocol (skuld v0.1.13)

View Source

Protocol for handling sentinel values in run/run! and generic sentinel inspection.

Sentinels are control flow values (Suspend, Throw, etc.) that bypass normal computation flow. This protocol allows generic handling without coupling to specific sentinel types.

Summary

Types

t()

All the types that implement this protocol.

Functions

Get the resume function if this sentinel is resumable, nil otherwise.

Complete a computation result - invoke leave_scope or bypass for sentinels

Extract value or raise for sentinel types

Is this a sentinel value? Returns false for plain values.

Get the serializable payload (struct fields minus :resume). Used for logging/serialization.

Return a new sentinel with the resume function replaced. Returns unchanged if not resumable.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

get_resume(sentinel)

@spec get_resume(t()) :: (term() -> {term(), Skuld.Comp.Types.env()}) | nil

Get the resume function if this sentinel is resumable, nil otherwise.

run(result, env)

Complete a computation result - invoke leave_scope or bypass for sentinels

run!(value)

@spec run!(t()) :: term()

Extract value or raise for sentinel types

sentinel?(value)

@spec sentinel?(t()) :: boolean()

Is this a sentinel value? Returns false for plain values.

serializable_payload(sentinel)

@spec serializable_payload(t()) :: map()

Get the serializable payload (struct fields minus :resume). Used for logging/serialization.

with_resume(sentinel, new_resume)

@spec with_resume(t(), (term() -> {term(), Skuld.Comp.Types.env()})) :: t()

Return a new sentinel with the resume function replaced. Returns unchanged if not resumable.