[erlang-questions] can flush the shell but can't receive from it

Steve Vinoski <>
Mon Nov 17 22:46:04 CET 2014


On Mon, Nov 17, 2014 at 4:38 PM, <> wrote:

> Hi,
>
> I have the simplest of applications that consists of just the skeleton
> gen_server, registered locally as "server", with one callback implemented:
>
>   handle_info({From, A, B}, State) ->
>     From ! {self(), A + B},
>     {noreply, State};
>
> i.e. a simple adder
>
> The supervisor is the skeleton one_for_one supervisor. The application,
> app, the skeleton application.
>
> Here is what I do:
>
> 7> application:start(app).
> ok
> 8> server ! {self(), 1, 2}.
> {<0.32.0>,1,2}
> 9> receive X -> X end.
> {<0.62.0>,3}
>

Here you bind X to the tuple value consisting of the server pid and the
value 3.


> 10> server ! {self(), a, b}.
>
> =ERROR REPORT==== 17-Nov-2014::22:18:42 ===
> ** Generic server server terminating
> ** Last message in was {<0.32.0>,a,b}
> ** When Server state == {state}
> ** Reason for termination ==
> ** {badarith,[{server,handle_info,2,[{file,"server.erl"},{line,98}]},
>               {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,
> 599}]},
>               {proc_lib,init_p_do_apply,3,
>                         [{file,"proc_lib.erl"},{line,239}]}]}
> {<0.32.0>,a,b}
> 11> server ! {self(), 3, 4}.
> {<0.32.0>,3,4}
> 12> receive X -> X end.
>
> and here the shell blocks.
>

It blocks because you're asking to receive the value of X you bound
earlier, which doesn't match what's in the mailbox.

--steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141117/74c1d044/attachment.html>


More information about the erlang-questions mailing list