Jido.Exec.Chain (Jido v1.2.0)
View SourceProvides 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
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}
whereresult
is 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:async
option is set totrue
.