Package published to finitomata | Hex
(25ec5990045d025fba2bb1c59a92e08fc8a045fdd347fcdcb885f22c75a1f2d2)
Introduces Infinitomata
module as a drop-in replacement of Finitomata.{start_fsm/4,transition/4,state/3}
. It transparently runs in a cluster, leveraging process groups :pg
to keep track of spawned instances.
Example from tests:
defmodule InfinitomataTest do
use ExUnit.Case, async: true
@moduletag :distributed
setup do
{_peers, _nodes} = Enfiladex.start_peers(3) # start 3 peers
Enfiladex.block_call_everywhere(Infinitomata, :start_link, [])
end
test "many instances (distributed)" do
for i <- 1..10 do
Infinitomata.start_fsm("FSM_#{i}", Finitomata.Test.Log, %{instance: i})
end
assert Infinitomata.count(Infinitomata) == 10
for i <- 1..10 do
Infinitomata.transition("FSM_#{i}", :accept)
end
assert %{"FSM_1" => %{}} = Infinitomata.all(Infinitomata)
for i <- 1..10 do
Infinitomata.transition("FSM_#{i}", :__end__)
end
Process.sleep(1_000)
assert Infinitomata.count(Infinitomata) == 0 # all finished ending state
assert Infinitomata.all(Infinitomata) == %{}
end
end