The mailbox is always stored in the order in which messages are received.
However, the order in which messages are used is determined by your code.
If you have a simple process with a general receive clause that receives something, the order in which you receive messages is the same as the order in which they were received.
loop() -> receive Any -> do_something(Any), loop() end.
However, if you have a selective receive with sentences with a word, it will look for a mailbox for messages of this particular type and consume the first relevant message, effectively skipping inappropriate messages. In the following example, if there are messages marked as important in the queue, they will be processed before any other message. Note. Matching this way will search for all messages in the queue, which is a problem for many messages. There have been some changes in this area, but I'm not ready for speed.
loop() -> receive {important, Stuff} -> do_something_important(Stuff), loop(); Any -> do_something(Any) loop() end.
knutin
source share