gen_statem and “co-located”

I’ve been playing with gen_statem lately through the elixir wrapper GenStateMachine. Things are going well, but I can’t figure out one part of the original gen_statem documentation:

gen_statem has got the same features that gen_fsm had and adds some really useful:

  • Co-located state code
  • Arbitrary term state
  • Event postponing
  • Self-generated events
  • State time-out
  • Multiple generic named time-outs
  • Absolute time-out time
  • Automatic state enter calls
  • Reply from other state than the request, sys traceable
  • Multiple sys traceable replies

I get all but the first: “co-located state code”. Does anyone know what co-located is referring to in this context?

:wave:

There’s a note about it later in the docs:

When the callback mode is state_functions, the state must be an atom and is used as the state callback name; see Module:StateName/3. This co-locates all code for a specific state in one function as the gen_statem engine branches depending on state name.

2 Likes

Dammit…I thought I read everything three times…sorry about missing that, but thanks for pointing it out! :grin:

1 Like