Raxol. Workflow. Execution. Scratchpad
(Raxol v2.6.0)
View Source
Per-task execution state for workflow runs that use interrupt / resume.
The scratchpad holds a FIFO of resume values supplied by callers of
Raxol.Workflow.Compiled.resume/4. When a node calls
Raxol.Workflow.interrupt/1, that function inspects the scratchpad:
- If the queue holds a value, the value is popped and returned; the node continues execution with that value (this is the resume path).
- If the queue is empty,
interrupt/1throws{:__workflow_interrupt__, value}, which the runtime catches and surfaces to the caller as{:interrupted, run_id, state, value}(this is the first-pause path).
Storage
Per-process storage uses the process dictionary under the
:raxol_workflow_scratchpad key. This is one of the rare cases
where the process dictionary is the right tool: the scratchpad is
process-local by construction, lives only for the duration of one
run's execution in one process, and must not leak between runs.
Runtime.invoke/3 clears the scratchpad on entry and exit so the
ambient state is always either the current run's or absent.
Summary
Functions
Remove the scratchpad from the process dictionary.
Return the current scratchpad, or nil if none is set.
Initialize the scratchpad for run_id, optionally seeding the resume
queue with the supplied list of values in order.
Pop the head of the resume queue.
Types
@type t() :: %{run_id: binary() | nil, resume_queue: :queue.queue()}
Per-process scratchpad state. Opaque to callers.
Functions
@spec clear() :: :ok
Remove the scratchpad from the process dictionary.
@spec get() :: t() | nil
Return the current scratchpad, or nil if none is set.
Initialize the scratchpad for run_id, optionally seeding the resume
queue with the supplied list of values in order.
Subsequent calls overwrite any prior scratchpad on the same process.
@spec take_resume() :: {:ok, any()} | :empty
Pop the head of the resume queue.
Returns {:ok, value} if a value was available, :empty otherwise.
Safe to call without init/2; treats the absence of a scratchpad as
an empty queue.