2008/5/27 Marcin Maciukiewicz <<a href="mailto:ciukes2@gmail.com">ciukes2@gmail.com</a>>:<br>> Hi,<br>><br>> This are my first steps in Erlang World. So far I'm stuck with<br>> gen_server:Module:handle_call/3.<br>
%> I get time out every time when {noreply, State} is returned. Following<br>> are code snippets:<br>> * Server module: <a href="http://pastebin.com/f590f0e00">http://pastebin.com/f590f0e00</a><br>> * Test module: <a href="http://pastebin.com/f2af1806b">http://pastebin.com/f2af1806b</a><br>
> * Console output: <a href="http://pastebin.com/f3b998308">http://pastebin.com/f3b998308</a><br>><br>> As I understand, the correct value is returned from handle_call/3. No<br>> problem with that. What I cannot determine is a reason for the time<br>
> out error.<br><br>The possible return values from the handle_call/3 function are:<br><br><span style="font-family: courier new,monospace;">%%--------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">%% Function: handle_call/3</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">%% Description: Handling call messages</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">%% Returns: {reply, Reply, State}          |</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">%%          {reply, Reply, State, Timeout} |</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">%%          {noreply, State}               |</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">%%          {noreply, State, Timeout}      |</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">%%          {stop, Reason, Reply, State}   | (terminate/2 is called)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">%%          {stop, Reason, State}            (terminate/2 is called)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">%--------------------------------------------------------------------</span><br style="font-family: courier new,monospace;"><br>If you use {noreply, State} or {noreply, State, Timeout}, then  you have to at some point invoke gen_server:reply/2 to return a reply to the caller. This is to allow the server process to continue doing something while possibly waiting for something to finish.<br>
<br>If you want to return a reply immediately, return {reply, Reply, State} or {reply, Reply, State, Timeout} from your handle_call/3 callback.<br><br>This page in the online documentation describes the various options pretty well.<br>
<br><a href="http://www.erlang.org/doc/design_principles/gen_server_concepts.html#2">http://www.erlang.org/doc/design_principles/gen_server_concepts.html#2</a><br><br>cheers<br>Chandru<br><br>