mudasobwa
Creator of Cure
Finitomata provides a boilerplate for FSM implementation, allowing to concentrate on the business logic rather than on the process management and transitions/events consistency tweaking.
It reads a description of the FSM from a string in PlantUML format.
It validates the FSM is consistent, namely it has a single initial state, one or more final states, and no orphan states. If everything is OK, it generates a GenServer that could be used both alone, and with provided supervision tree. This GenServer requires to implement three callbacks
on_transition/4— mandatoryon_failure/3— optionalon_terminate/1— optional
All the callbacks do have a default implementation, that would perfectly handle transitions having a single to state and not requiring any additional business logic attached.
Example:
defmodule MyFSM do
@fsm """
[*] --> s1 : to_s1
s1 --> s2 : to_s2
s1 --> s3 : to_s3
s2 --> [*] : ok
s3 --> [*] : ok
"""
use Finitomata, @fsm
def on_transition(:s1, :to_s2, event_payload, state_payload),
do: {:ok, :s2, state_payload}
end
Trending in Announcing
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
I released Doggo, a collection of unstyled Phoenix components.
https://github.com/woylie/doggo
Features
Unstyled Phoenix components....
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
Hey folks,
I just published a post about Hologram’s funding and where the project goes next - the short version:
Curiosum as Main Spons...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mmmries
@mudasobwa thanks for sharing this library, I’ve used
gen_statema few times in the past and I think your library makes these kinds of use-cases a lot more ergonomic. Have you ever thought making a compile-time dependency, rather than a runtime dependency?My thought here is that I could use something like finitomata to help me develop a FSM module, but I could generate an elixir/erlang file with all of the expansion done so that I don’t have to specify finitomata as a dependency of my library. This also means that other libraries could use different versions of the tool without need to resolve to a shared version.
Just curious if you’ve considered a use-case like that, or maybe I should give it a try myself to see how it goes?
mudasobwa
Well, there is no runtime dependency already, besides provided supervision subtree, registry, and helpers to deal with dynamic children.
If you don’t need all the above and are ready to manage the processes yourselves, you don’t depend on
Finitomatain runtime.use Finitomatainjects the code into your module in compile time. Generating this boilerplate code instead of injecting is not a big deal, a simple call toMacro.to_string/1would do (e. g. from__before_compile__callback.)mixtask to generate such a module is also trivial. I personally don’t like generators because the code they produce is hard to support, code injection works better. But I’d love to see a PR with amixtask generating the module.mudasobwa
FWIW, this thread contains links to other similar libraries and usage examples.
mmmries
Thanks @mudasobwa your breakdown definitely improved my thinking. I can see how a generator might be a pain to deal with in source control etc. And the distinction between run-time, compile-time and deploy-time is helpful as well. Thanks again for the library, I’ll give it a run
mudasobwa
After some hesitation, two new callbacks have been added.
on_enter/2— optionalon_exit/2— optionalmudasobwa
Introduces
Infinitomatamodule as a drop-in replacement ofFinitomata.{start_fsm/4,transition/4,state/3}. It transparently runs in a cluster, leveraging process groups:pgto keep track of spawned instances.Example from tests:
mudasobwa
FinitomatagotThrottler, fully obsoletingSiblings.Last version transparently runs on distributed erlang with the ability to throttle transitions, if necessary.
mudasobwa
Another blog post about
Finitomata.mudasobwa
To support my own rant about making our libraries test-friendly (based on
finitomataexample), I implemented the test scaffold generation, based on the FSM shape, collected during the compile time.The above would generate a scaffold for checking all the possible paths in the FSM declaration. Enjoy.
lud
(this topic should have the
finitomatatag)I read your blog post about workflows, it was very interesting, thank you.
I never use libraries for FSMs because in my mind you don’t always know what is the next state when you handle an event. I think it’s weird to have both
closed ‑- button press --> openandclosed -- button press --> lockedside by side, although it is the actual behaviour.Probably I’m not using those tools correctly.
If you have some time, could you demo a door that opens when 4 digit button presses are correctly in order (the door code is
1234obviously), but locks for 100ms seconds if 10 unsuccessful buttons are pressed (0001234opens,00011101234locks the door after3and ignores presses for 30 sec so4is ignored). Door stays open for 50ms or so.I could ask Claude to do it but I’d really like to see how you would do it!