Cizen.Automaton behaviour (Cizen v0.18.1) View Source

A saga framework to create an automaton.

Handle requests from Saga.call/2 and Saga.cast/2:

case perform(%Receive{}) do
  %Automaton.Cast{request: {:push, item}} ->
    [item | state]

  %Automaton.Call{request: :pop, from: from} ->
    [head | tail] = state
    Saga.reply(from, head)
    tail
end

Link to this section Summary

Callbacks

Invoked when the automaton is resumed.

Invoked when the automaton is spawned. Saga.Started event will be dispatched after this callback.

Invoked when other callbacks returns a next state.

Link to this section Types

Specs

finish() :: {Cizen.Automaton, :finish}

Specs

state() :: term()

Link to this section Functions

Link to this function

handle_call(request, from, handler)

View Source
Link to this function

handle_cast(request, handler)

View Source
Link to this function

handle_event(event, handler)

View Source

Performs an effect.

perform/1 blocks the current block until the effect is resolved, and returns the result of the effect.

Note that perform/1 does not work only on the current process.

Link to this section Callbacks

Specs

respawn(Cizen.Saga.t(), state()) :: finish() | state()

Invoked when the automaton is resumed.

Returned value will be used as the next state to pass yield/1 callback. Returning Automaton.finish() will cause the automaton to finish.

This callback is predefined. The default implementation is here:

def respawn(saga, state) do
  spawn(saga)
  state
end

Specs

spawn(Cizen.Saga.t()) :: finish() | state()

Invoked when the automaton is spawned. Saga.Started event will be dispatched after this callback.

Returned value will be used as the next state to pass yield/1 callback. Returning Automaton.finish() will cause the automaton to finish.

If not defined, default implementation is used, and it passes the given saga struct to yield/1 callback.

Specs

yield(state()) :: finish() | state()

Invoked when other callbacks returns a next state.

Returned value will be used as the next state to pass yield/1 callback. Returning Automaton.finish() will cause the automaton to finish.

If not defined, default implementation is used, and it returns Automaton.finish().