[erlang-questions] [gen_server] time out error when handle_call returns {noreply, State}

Taavi Talvik taavi@REDACTED
Wed May 28 10:29:06 CEST 2008


On May 28, 2008, at 10:37 AM, Marcin Maciukiewicz wrote:

> Thank both of you guys for help. So far I understand what you say, but
> I'm not sure how it may help.
> In the following code, last executed line is #14. After that VM hangs
> for 5 sec thus I don't see a reasonable place to put

No, no! VM does not hang!

All other processes continue normally! In Erlang you have thousands
of processes;) You can dedicate some of them for doing actual work..

Only your calling process is suspended until answer is available or
specifed timeout happens (which defaults to 5s).

>
> gen_server:reply/2. call.
> http://pastebin.com/f590f0e00
>
> I feel I need an extra push to understand. The reason why I play with
> {noreply, State} is because I want to understand how to deal with this
> case.

example:

handle_call({alloc, Pid}, From, State) ->
  actual_worker_process ! {please_calculate_reply_for_client, From,  
{alloc,Pid}},
  {noreply, State}.

and in actual_worker_proccess

start_worker() ->
    Pid = spawn(worker_loop),
    register(actual_worker_process, Pid).

worker_loop() ->
     receive
       {please_calculate_reply_for_client, Client, Args} ->
	  Result = .....(Args),
           gen_server:reply(Client, Result)
     end,
     worker_loop().

best regards,
taavi




More information about the erlang-questions mailing list