문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top