简体   繁体   中英

order of arrival of message on a mailboxprocessor

Is there /How can I get guarantee on the order of arrival for the messages sent to a mailboxprocessor

That is, on a thread if I do

agent.post(msg1)
agent.post(msg2)

How can I be sure that, in the treatment loop for the agent, the messages will be received in order ?

They are. The implementation of Post is as you might guess, it just adds an item to the queue (on the current thread, under a lock), and posts work to notify any waiting agent to wake up and process it. So if you call Post twice on the same thread, one after another, the messages get into the queue in that order.

You can also use inbox.Scan(function _ -> None // return an Option) to find the messages if you have some way of detecting order. Of course, this comes at a price to performance, so leaving the queue alone is the best idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM