[erlang-questions] The gen server simplified (how it works)

Ulf Wiger ulf.wiger@REDACTED
Thu Apr 21 18:30:20 CEST 2011

I'd love to see how you handle system messages in two lines of code, without reusing some library. :)

Usually, it involves writing your own versions of system_continue/3, system_terminate/4,  system_code_change/4, and format_status/2.

Ulf W

On 21 Apr 2011, at 18:14, Håkan Mattsson wrote:

> I gladly write two lines of code to handle system
> messages, if that enables me to avoid a boring
> template. I really like the simplicity of Joe's code
> snippet. It is easy to understand and does not
> imply any black magic. It is just proc_lib that is
> missing...
> /Håkan
> PS. You did also have two "boring" lines in your
> template to handle code change.
> "Ulf Wiger" <ulf.wiger@REDACTED> wrote:
>> Personally, I like to use plain_fsm, so I don't have to worry about
>> writing that boring code to handle system messages.
>> https://github.com/esl/plain_fsm
>> It doesn't force you to use the parse transformery and pseudo
>> functions; you can e.g. use 
>> https://github.com/esl/plain_fsm/blob/master/doc/plain_fsm.md#handle_system_msg-4
>> and simply have plain_fsm as a library for those system message
>> handlers.
>> BR,
>> Ulf W
>> On 21 Apr 2011, at 16:32, Håkan Mattsson wrote:
>>> I tend to use proc_lib (spawn_link, start_link, init_ack) and sys
>>> (handle_system_msg) a lot. They gives you almost all the bells and
>>> whistles that gen_server has, but it enables you to have the same
>>> simple code structure that you have in your very pedagogic code
>>> snippet below.
>> Ulf Wiger, CTO, Erlang Solutions, Ltd.
>> http://erlang-solutions.com
> -- 
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Ulf Wiger, CTO, Erlang Solutions, Ltd.

More information about the erlang-questions mailing list