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

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.

Sentinel Categories

Sentinels fall into two categories:

  • Suspend sentinels (suspend?/1 returns true): ExternalSuspend, InternalSuspend These represent suspended computations that can be resumed.

  • Error sentinels (error?/1 returns true): Throw, Cancelled These represent error conditions that propagate up the call stack.

Plain values have sentinel?/1, suspend?/1, and error?/1 all return false.

Summary

Types

t()

All the types that implement this protocol.

Functions

Is this an error sentinel (Throw, Cancelled)?

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.

Is this a suspend sentinel (ExternalSuspend, InternalSuspend)?

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

error?(value)

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

Is this an error sentinel (Throw, Cancelled)?

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.

suspend?(value)

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

Is this a suspend sentinel (ExternalSuspend, InternalSuspend)?