[erlang-questions] module vs gen_server
Vance Shipley
vances@REDACTED
Thu Jan 26 06:53:10 CET 2017
On Thu, Jan 26, 2017 at 3:45 AM, Charles Shuller
<charles.shuller@REDACTED> wrote:
> What things should be considered when deciding if a chunk of functionality
> should be implemented as a plain old module or a gen_server??
Think of the process(es) which will execute the code providing the
functionality. If existing processes will call functions in your
module and execute that code inline than it is a library module and
needs no behavior.
If the functionality will be provided by executing the code in a new
process than you should consider how you will handle system messages
in that process. If you don't yet know what that means you should use
one of the standard behaviors which will provide everything you need
to behave correctly in OTP. If you don't like to play it safe you can
handle system messages in a "plain old module"
(http://erlang.org/doc/man/sys.html).
The more common question is: should I use a gen_server or a gen_fsm
(or gen_statem) behavior? If you start with a gen_server and later
realize you need to handle an event differently based on something in
a previous event than your server has states and you should port it to
a gen_fsm (or gen_statem).
--
-Vance
More information about the erlang-questions
mailing list