Are messages sent by subsequent tell
invocations guaranteed to be processed by the actor in the order in which they were sent?
Example:
actor ! message1
actor ! message2
Will message1
and message2
be always seen by the actor in the order in which they were sent.
CodePudding user response:
If message1
and message2
are sent in that order from the same thread, or from the same actor and they are sent to the same actor (and that actor is using a mailbox that does not reorder messages: the default mailbox does not, but one can implement mailboxes which reorder messages, e.g. in order to implement prioritization), message2
will not be received by the target actor before message1
.
Thus any of the of these four is possible:
message1
is received and thenmessage2
message1
is received, butmessage2
is never receivedmessage1
is never received, butmessage2
is- neither
message1
normessage2
is ever received
Note that there is no guarantee that two message sends to different actors will be received in any particular order. There is also no guarantee regarding the ordering of message sends from two different actors (or if outside of any actor (e.g. in a Future
callback or the main method), a different thread)).