[erlang-questions] module vs gen_server
Jesper Louis Andersen
Thu Jan 26 14:28:18 CET 2017
On Thu, Jan 26, 2017 at 5:20 AM Charles Shuller <charles.shuller@REDACTED>
> What things should be considered when deciding if a chunk of functionality
> should be implemented as a plain old module or a gen_server??
As a main rule:
Stateless functionality goes into library modules, stateful functionality
goes into a gen_server process.
A good example is a database pool. The protocol encoder/decoder for the
database is a library and should live separately. A stateful connection to
the DB uses the protocol module to provide its functionality. Finally, a
separate system handles the pooling and its guarantees.
By splitting the system up, you can reuse the DB connection code in another
pool. Or you can move the connection handling into another process by
calling directly into the library.
Another main rule:
Each concurrent activity which needs to keep state must have its own
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions