[erlang-questions] gen_server Question

Kresten Krab Thorup krab@REDACTED
Mon Aug 2 10:51:03 CEST 2010


I agree with the commenters.  Use generic behavior whenever there is no compelling reason to not do it.  

An important reason for this is that it makes the resulting code more easy to read for other erlangers, and because it provides leverage for future enhancements of the platform.  

One such example is the new instructions in R14 that improve performance of rpc done from inside a gen server - you don't have to do anything, but the system behaves better under stress.  Likewise, the level of indirection provided by using a generic behavior could be the foundation for other future optimizations, or operational pleasantries.

Kresten


On Aug 1, 2010, at 2:08 , Behdad Forghani wrote:

> Hello,
> 
> 
> 
> I am writing a module that mostly monitors a directory at certain intervals
> and processes the files that are dropped into that directory and sends
> messages to another process. I want this processes to be supervised. Two
> options come into my mind:
> 
> 
> 
> 1 - Write a server myself, similar to server4.erl in Joe Armstrong's
> "Programming Erlang" book. In this case, I will use an "after Time ->"
> clause.
> 
> 2 - Use gen_server behavior and use timer module to send messages to myself,
> since, I do not see any other way to get regular timeouts.
> 
> 
> 
> My question is, shall I try to use gen_server? Do I get anything extra by
> using gen_server? I do not need multicall and I can write my own terminate
> routine. Is there anything else that I will be missing?
> 
> 
> 
> Thanks in advance.
> 
> Behdad
> 
> 
> 

Kresten Krab Thorup, CTO, Trifork



More information about the erlang-questions mailing list