[erlang-questions] Receive with priority [yet again]

Álvaro avalormaquedano@REDACTED
Thu Jan 24 15:49:03 CET 2013


Hi all,

I want to know what is the current implementation of Erlang's receive
statement.

I need to implement a system where two priorities can be given to messages
(high and normal). I need to, first, process all high priority messages and
then return the first normal priority one (if any). I wonder which its best
implementation can be:

process_all_messages()->
      receive
            {high_priority, Message} ->  % <--- Pattern1
                        process_message(Message),
                        process_all_messages()
     after
           0 ->
             receive
                       {normal_priority, Message} -> % <--- Pattern2
                                              Message
             after
                    0 ->
                       no_messages
            end
     end.


This function will be called periodically and I need to know if this
implementation will always go through all the message in the mailbox (i.e.
it will try to match Pattern1 to the messages at the beginning of the
mailbox over and over again).

Is there any recent improvement?


Will I get any gain by implementing my own priority queue?


Thanks a lot,
Álvaro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130124/8f0f0fe9/attachment.htm>


More information about the erlang-questions mailing list