Search documentation of Finitomata

# View Source Finitomata.Persistency behaviour (Finitomata v0.22.1)

The behaviour to be implemented by a persistent storage to be used with `Finitomata` (pass the implementation as `persistency: Impl.Module.Name` to `use Finitomata`.)

Once declared, the initial state would attempt to load the current state from the storage using `load/1` funtcion which should return the `{state, payload}` tuple.

# Summary

## Types

transition_info()

## Callbacks

load(id)

The function to be called from `init/1` callback upon FSM start to load the state and payload from the persistent storage

store(id, object, transition)

The function to be called from `on_transition/4` handler to allow storing the state and payload to the persistent storage

store_error(id, object, reason, transition)

The function to be called from `on_transition/4` handler on non successful transition to allow storing the failed attempt to transition to the persistent storage

# Types

Link to this type

# transition_info()

View Source

    @type transition_info() :: %{
      from: Finitomata.Transition.state(),
      to: Finitomata.Transition.state(),
      event: Finitomata.Transition.event(),
      event_payload: Finitomata.event_payload(),
      object: Finitomata.State.payload()
    }

# Callbacks

Link to this callback

# load(id)

View Source

    @callback load(id :: Finitomata.fsm_name()) ::
      {:loaded | :created | :unknown, Finitomata.State.payload()}

The function to be called from `init/1` callback upon FSM start to load the state and payload from the persistent storage

Link to this callback

# store(id, object, transition)

View Source

    @callback store(
      id :: Finitomata.fsm_name(),
      object :: Finitomata.State.payload(),
      transition :: transition_info()
    ) :: :ok | {:ok, Finitomata.State.payload()} | {:error, any()}

The function to be called from `on_transition/4` handler to allow storing the state and payload to the persistent storage

Link to this callback

# store_error(id, object, reason, transition)

View Source (optional)

    @callback store_error(
      id :: Finitomata.fsm_name(),
      object :: Finitomata.State.payload(),
      reason :: any(),
      transition :: transition_info()
    ) :: :ok | {:error, any()}

The function to be called from `on_transition/4` handler on non successful transition to allow storing the failed attempt to transition to the persistent storage