Skip to content

Instantly share code, notes, and snippets.

@leikind
Created January 5, 2015 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leikind/4ee0e1303e7b67c08af7 to your computer and use it in GitHub Desktop.
Save leikind/4ee0e1303e7b67c08af7 to your computer and use it in GitHub Desktop.
Cat FSM

DECEMBER 13, 2011

As a continuation of my previous post about the chapter Rage Against The Finite-State Machines from Learn You Some Erlang for Great Good here is a gen_fsm implementation for the Cat's FSM described in the chapter.

This is a primitive one-state FSM, but the difference is that synchronous calls are used.

leikind/1483379

The output:

27> c(cat_fsm).
{ok,cat_fsm}
28> cat_fsm:test().
Switching to 'dont_give_crap' state
<0.145.0>
Cat replied: ok
Switching to 'dont_give_crap' state
Cat replied: ok
Switching to 'dont_give_crap' state
Cat replied: ok
Cat receives an unknown global sync event: hello
Cat receives an unknown global event: how_are_you
terminating with reason normal at state dont_give_crap
29>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment