简体   繁体   English

消息到达邮箱处理器的顺序

[英]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. Post的实现就像你猜测的那样,它只是在队列中添加一个项目(在当前线程上,在锁定下),并且post工作以通知任何等待代理唤醒和处理它。 So if you call Post twice on the same thread, one after another, the messages get into the queue in that order. 因此,如果您在同一个线程上一次又一次地调用Post ,则消息将按此顺序进入队列。

You can also use inbox.Scan(function _ -> None // return an Option) to find the messages if you have some way of detecting order. 如果您有某种检测顺序的方法,也可以使用inbox.Scan(function _ -> None // return an Option)来查找消息。 Of course, this comes at a price to performance, so leaving the queue alone is the best idea. 当然,这会带来性能代价,因此单独排队是最好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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