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:
message1is received and thenmessage2message1is received, butmessage2is never receivedmessage1is never received, butmessage2is- neither
message1normessage2is 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)).
