Statex
<img src="https://travis-ci.com/RstorLabs/statex.svg?branch=master">
General State Machine for Elixir
Using Statex is easy, you just have to define a @state_graph.
defmodule LightSwitch do
use Statex
@state_graph off: [flip: :on],
on: [flip: :off]
end
iex> {:ok, pid} = LightSwitch.start_link()
...
iex> LightSwitch.state(pid)
:off
iex> LightSwitch.flip(pid)
:ok
iex> LightSwitch.state(pid)
:on
iex> LightSwitch.flip(pid)
:ok
iex> LightSwitch.state(pid)
:offInstallation
The package can be installed by adding Statex to your list of dependencies
in mix.exs:
def deps do
[
{:statex, github: "RstorLabs/statex"}
]
end