View Source Reactor (reactor v0.2.0)

Reactor is a dynamic, concurrent, dependency resolving saga orchestrator.

usage

Usage

You can construct a reactor using the Reactor Spark DSL:

defmodule HelloWorldReactor do
  @moduledoc false
  use Reactor

  input :whom

  step :greet, Greeter do
    argument :whom, input(:whom)
  end

  return :greet
end
iex> Reactor.run(HelloWorldReactor, %{whom: "Dear Reader"})
{:ok, "Hello, Dear Reader!"}

or you can build it programmatically:

iex> reactor = Builder.new()
...> {:ok, reactor} = Builder.add_input(reactor, :whom)
...> {:ok, reactor} = Builder.add_step(reactor, :greet, Greeter, whom: {:input, :whom})
...> {:ok, reactor} = Builder.return(reactor, :greet)
...> Reactor.run(reactor, %{whom: nil})
{:ok, "Hello, World!"}

Link to this section Summary

Link to this section Types

@type context() :: Enumerable.t({any(), any()})
@type inputs() :: %{optional(atom()) => any()}
@type options() ::
  Enumerable.t(
    {:max_concurrency, pos_integer()}
    | {:timeout, pos_integer() | :infinity}
    | {:max_iterations, pos_integer() | :infinity}
    | {:halt_timeout, pos_integer() | :infinity}
  )
@type state() :: :pending | :executing | :halted | :failed | :successful
@type t() :: %Reactor{
  context: context(),
  inputs: [atom()],
  intermediate_results: %{required(any()) => any()},
  plan: nil | Graph.t(),
  return: any(),
  state: state(),
  steps: [Reactor.Step.t()],
  undo: [{Reactor.Step.t(), any()}]
}

Link to this section Functions

Link to this function

default_extension_kinds()

View Source

Callback implementation for Spark.Dsl.explain/2.

Link to this function

handle_before_compile(opts)

View Source

Callback implementation for Spark.Dsl.handle_before_compile/1.

Callback implementation for Spark.Dsl.handle_opts/1.

Callback implementation for Spark.Dsl.init/1.

Link to this function

run(reactor, inputs \\ %{}, context \\ %{}, options \\ [])

View Source
@spec run(t() | module(), inputs(), context(), options()) ::
  {:ok, any()} | {:error, any()} | {:halted, t()}

Run a reactor.

Link to this function

single_extension_kinds()

View Source