{"id":13507248,"url":"https://github.com/pavlos/gen_fsm","last_synced_at":"2025-04-15T16:56:23.933Z","repository":{"id":57501674,"uuid":"55214522","full_name":"pavlos/gen_fsm","owner":"pavlos","description":"Elixir wrapper around OTP's gen_fsm","archived":false,"fork":false,"pushed_at":"2020-03-03T22:27:24.000Z","size":22,"stargazers_count":40,"open_issues_count":5,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T03:46:40.987Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pavlos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-01T08:01:23.000Z","updated_at":"2024-08-03T15:12:05.000Z","dependencies_parsed_at":"2022-09-19T09:10:59.336Z","dependency_job_id":null,"html_url":"https://github.com/pavlos/gen_fsm","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavlos%2Fgen_fsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavlos%2Fgen_fsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavlos%2Fgen_fsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavlos%2Fgen_fsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pavlos","download_url":"https://codeload.github.com/pavlos/gen_fsm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249116133,"owners_count":21215140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:28.670Z","updated_at":"2025-04-15T16:56:23.912Z","avatar_url":"https://github.com/pavlos.png","language":"Elixir","funding_links":[],"categories":["Algorithms and Data structures"],"sub_categories":[],"readme":"\u003cimg align=\"right\" src=\"http://i.imgur.com/OEtTdfe.png\"\u003e\n\n# GenFSM\n\nElixir wrapper around Erlang's OTP gen_fsm.\n\n\n## Motivation\n\nElixir [deprecated](https://github.com/elixir-lang/elixir/commit/455eb4c4ace81ce60b347558f9419fe3c33d8bf7)\nits wrapper around OTP's gen_fsm from the standard library because it is difficult to understand and suggested that\ndevelopers seek other finite state machine implementations.\n\nThis is understandable, but some of us still need/prefer to use the OTP gen_fsm.\n\nI took the basis of Elixir's old\n[GenFSM.Behaviour](https://github.com/elixir-lang/elixir/blob/a6f048b3de4a971c15fc8b66397cf2e4597793cb/lib/elixir/lib/gen_fsm/behaviour.ex)\nand added some additional convenience methods.  Currently missing are the `enter_loop` methods.\n\n## Usage\n\nThe following example implement a simple state machine with two states, `martin` and `paul`. The state machine will initialize into the `martin` state, when the state machine receive `:hello` as the input it will transition between the states, from `martin` to `paul` and `\"Hello, Paul\"` will get printed to the console.\n\n```elixir\ndefmodule Conversation do\n  use GenFSM\n\n  def start_link() do\n    GenFSM.start_link(__MODULE__, :na)\n  end\n\n  def hello(pid) do\n    GenFSM.send_event(pid, :hello)\n  end\n\n  def init(:na), do: {:ok, :martin, nil}\n\n  def martin(:hello, nil) do\n    IO.puts \"Hello, Paul\"\n    {:next_state, :paul, nil}\n  end\n\n  def paul(:hello, nil) do\n    IO.puts \"Hello, Martin\"\n    {:next_state, :martin, nil}\n  end\nend\n```\n\nA conversation could go like this:\n\n``` elixir\niex(2)\u003e {:ok, pid} = Conversation.start_link\n{:ok, #PID\u003c0.165.0\u003e}\niex(3)\u003e Conversation.hello pid\nHello, Paul\n:ok\niex(4)\u003e Conversation.hello pid\nHello, Martin\n:ok\niex(5)\u003e\n```\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed as:\n\n  1. Add gen_fsm to your list of dependencies in `mix.exs`:\n\n        def deps do\n          [{:gen_fsm, \"~\u003e 0.1.0\"}]\n        end\n\n## Documentation\n\nComplete [API documentation](http://erlang.org/doc/man/gen_fsm.html) can be found at\nhttp://erlang.org/doc/man/gen_fsm.html\nand OTP [design principal documentation](http://erlang.org/doc/design_principles/fsm.html)\nlives at http://erlang.org/doc/man/gen_fsm.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpavlos%2Fgen_fsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpavlos%2Fgen_fsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpavlos%2Fgen_fsm/lists"}