Pregunta

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 ?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top