[erlang-questions] gen_server:call and hibernate

Ulf Wiger ulf.wiger@REDACTED
Thu May 19 18:47:28 CEST 2011


The subtle difference is that a gen_server:cast assumes a gen_server on the receiving end, and the request ends up in handle_cast/2. A plain message ends up in handle_info/2.

At least I tend to prefer cast for messages that are part of the internal protocol, leaving handle_info/2 for messages where I don't control the sending side.

BR,
Ulf W

On 19 May 2011, at 18:35, ag3nt911 wrote:

> Ulf,
> 
> Thanks! indeed, the gen_server:call is quite simple. I should have traced it
> and saw it for myself. Initially i thought a gen_server:cast would make more
> sense to use but what I couldn't grasp is why facebook developers would
> prefer gen_server:call over gen_server;cast instead. Is there any catch to
> using a method where:
> 
> TimerRef = erlang:start_timer(60000, self(), {timedout, Data}),
> %% gen_server:call(ServerPid, {message, SomeData}),
> Ref = erlang:monitor(process, ServerPid),
> ServerPid ! {call, {self(), Ref}, SomeData}, 
> proc_lib:hibernate(?MODULE, func, [TimerRef]).
> 
> as opposed to:
> 
> TimerRef = erlang:start_timer(60000, self(), {timedout, Data}),
> gen_server:cast(ServerPid, {message, SomeData}),
> proc_lib:hibernate(?MODULE, func, [TimerRef]).
> 
> 
> 
> --
> View this message in context: http://erlang.2086793.n4.nabble.com/gen-server-call-and-hibernate-tp3534336p3536301.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com






More information about the erlang-questions mailing list