Jido.Composer.Node.FanOutNode (Jido Composer v0.4.0)

Copy Markdown View Source

Executes multiple child nodes concurrently and merges their results.

FanOutNode encapsulates parallel execution behind the standard Node interface. It appears as a single state to the Workflow FSM but internally spawns multiple branches via Task.async_stream.

Merge Strategies

  • :deep_merge (default) — scopes each branch result under the branch name, then deep-merges into a single map
  • Custom function — receives [{branch_name, result}] and returns a map

Error Handling

  • :fail_fast (default) — returns {:error, reason} on first branch failure
  • :collect_partial — collects all results, including {:error, reason} entries

Summary

Functions

Merges branch results using the specified merge strategy.

Types

branch()

@type branch() :: {atom(), struct() | (map() -> Jido.Composer.Node.result())}

merge()

@type merge() :: :deep_merge | ([{atom(), map()}] -> map())

t()

@type t() :: %Jido.Composer.Node.FanOutNode{
  branches: [branch()],
  max_concurrency: pos_integer() | nil,
  merge: merge(),
  name: String.t(),
  on_error: :fail_fast | :collect_partial,
  timeout: pos_integer() | :infinity
}

Functions

merge_results(branch_results, merge)

@spec merge_results(%{required(atom()) => term()} | [{atom(), term()}], merge()) ::
  map()

Merges branch results using the specified merge strategy.

When called from the strategy with a completed_results map, converts to the keyword-list format expected by the merge logic.

new(opts)

@spec new(keyword()) :: {:ok, t()} | {:error, term()}