gen_server and priority queues

Dominic Williams xpdoka@REDACTED
Mon Oct 24 23:08:31 CEST 2005


Richard Cameron wrote:
> 
> I want to implement a server which processes messages in order of  
> priority. I know I can do this in pure Erlang as:
> 
> handle(high, State) ->
>     receive {high,Msg} ->
>             do(Msg,State)
>     after 0 ->
>             handle(medium, State)
>     end;
> handle(medium, State) ->
>     receive {medium,Msg} ->
>             do(Msg, State)
>     after 0 ->
>             handle(low, State)
>     end;
> handle(low, State) ->
>     receive {_,Msg} ->
>             do(Msg, State)
>     end.

Isn't this overkill? I was under the impression that:

receive
   {high, Msg} ->
      ...;
   {medium, Msg} ->
      ...;
   {low, Msg} ->
      ...;
end,

pulls higher priority messages out of the queue?

Cheers,

Dominic Williams
http://www.dominicwilliams.net

----



More information about the erlang-questions mailing list