Jido.Exec.Chain
(Jido Action v2.0.0)
View Source
Provides functionality to chain multiple Jido Execs together with interruption support.
This module allows for sequential execution of actions, where the output of one action becomes the input for the next action in the chain. Execution can be interrupted between actions using an interruption check function.
Examples
iex> interrupt_check = fn -> System.monotonic_time(:millisecond) > @deadline end
iex> Jido.Exec.Chain.chain([AddOne, MultiplyByTwo], %{value: 5}, interrupt_check: interrupt_check)
{:ok, %{value: 12}}
# When interrupted:
iex> Jido.Exec.Chain.chain([AddOne, MultiplyByTwo], %{value: 5}, interrupt_check: fn -> true end)
{:interrupted, %{value: 6}}
Summary
Functions
Executes a chain of actions sequentially with optional interruption support.
Types
@type chain_result() :: {:ok, map()} | {:error, Jido.Action.Error.t()} | {:interrupted, map()} | Task.t()
@type interrupt_check() :: (-> boolean())
Functions
@spec chain([chain_action()], map(), keyword()) :: chain_result()
Executes a chain of actions sequentially with optional interruption support.
Parameters
actions: A list of actions to be executed in order. Each action can be a module (the action module) or a tuple of{action_module, options}.initial_params: A map of initial parameters to be passed to the first action.opts: Additional options for the chain execution.
Options
:async- When set totrue, the chain will be executed asynchronously (default:false).:context- A map of context data to be passed to each action.:interrupt_check- A function that returns boolean, called between actions to check if chain should be interrupted.
Returns
{:ok, result}whereresultis the final output of the chain.{:error, error}if any action in the chain fails.{:interrupted, result}if the chain was interrupted, containing the last successful result.Task.t()if the:asyncoption is set totrue.