Reading Elixir in Action 2019, Ch 6. Page 165 Listing 6.8 discussing cast and handle_cast and wondering if the sequence in which receive
matches messages in the example can lead to a situation that a call
, sent immediately after cast
may somehow appear handled “out of sync” from the caller perspective.
Messages are handled in the order they are received. The order of matches in the receive
block has no effect on the order in which messages are handled. For each message received, it will run through each option in the receive
until it finds a match.
It cannot. When A sends B a message, B will always see messages from A in the order that A sent them. This is guaranteed.
Thank you for clearing my doubts!
I wish this was added to the receive/1 doc for other folks that come from the Golang world in which select
statement actually rolls the dice.
Feel free to contribute a change that would make it more clear. There is a link to the function source on the right of the function name in the docs, this thing: </>