[erlang-questions] EUC 2006 / proposal to enhance message receive

Roger Larsson <>
Tue Nov 14 07:24:10 CET 2006


On Tuesday 14 November 2006 04:49, Jay Nelson wrote:
> > It seems to me that your suggestion introduces a new syntax
> > without providing new semantics. Using send and selective
> > receive it is already possible, semantically, to have
> > messages of different priorities.
>
> Yes, you are right, I see that now.  I also see that I didn't handle
> priority properly.  It requires nested receives:
>
> receive ->
>    {priority_msg, Data1} -> priority(Data1)
> after
>    0 ->
>      receive
>        {normal_msg, Data2} -> normal(Data2)
>      after
>        0 -> none
>      end
> end.
>
> This pattern applies in the current syntax and in the syntax I proposed.
> The problem is you end up polling because you can't wait inside either
> of the nested receive clauses.
>

And a waiting version...

receive ->
   {priority_msg, Data1} -> priority(Data1)
after
   0 ->
     receive
	{priority_msg, Data1} -> priority(Data1)
       {normal_msg, Data2} -> normal(Data2)
     end
end.

I earlier proposed a slight syntax change, to avoid the repeated line. But 
should expand to the equivalent of the code above (with double receives).
[ie letting the after choice be a part of the guard]

receive ->
   {priority_msg, Data1} -> priority(Data1)
   {normal_msg, Data2} after 0 -> normal(Data2)
end.

/RogerL



More information about the erlang-questions mailing list