Reputation: 7139
In Erlang there are two behaviors that seem to be pretty similar:
-behaviour(gen_server).
-behaviour(gen_statem).
What is the practical difference? When should I use one over another?
Upvotes: 1
Views: 1106
Reputation: 3509
gen_server
stands for "generic server", and it's a framework/interface to build processes that handle requests and events.
gen_statem
stands for "generic state machine" and it's a framework/interface to build processes that behave as state machines reacting to events.
You could build a state machine on top of a gen_server
or have a single-state state machine acting as a server.
To choose between one and the other you should check the relevant chapter in the doc, but I'd narrow it down to:
If you need to model a state machine, consider the features provided by gen_statem
. For simple state machines without bells and whistles gen_server
works fine and it's simpler.
Upvotes: 3