[erlang-questions] gen_server behaviour

Ulf Wiger <>
Tue May 26 13:29:23 CEST 2009


Christian Axelsson wrote:
> 
> Ah, ofcourse! Thank you and Ulf for the quick response. The problem that
> I'm facing here is to make some legacy code that uses standard message
> passing (using !) to our OTP-styled app and I though that this would've
> been a clean enough way to do that.
> 
> Any suggestions on how to accomplish that? I suspect that it isn't a too
> uncommon problem that people face.

Break out the common code into a helper function.

handle_call(f, _From, State) ->
   {Reply, NewState} = huzza(f, State),
   {reply, Reply, NewState}.

handle_info(Msg, State) ->
   {From, Req} = Msg,  % let's say...
   {Reply, NewState} = huzza(Msg, State),
   From ! {self(), Reply},
   {noreply, NewState}.

...or something like that.

BR,
Ulf W

-- 
Ulf Wiger
CTO, Erlang Training & Consulting Ltd
http://www.erlang-consulting.com



More information about the erlang-questions mailing list