Can Actors in Scala fail to process messages? (example in O'Reilly's Programming Scala)

后端 未结 4 606
无人共我
无人共我 2020-12-18 11:15

I\'m completely new to Scala, and I\'ve been working my way through Programming Scala (O\'Reilly) online; while doing so, I was surprised by the result of the

4条回答
  •  醉酒成梦
    2020-12-18 11:38

    Actually, that seems reasonable enough. See, the actor is concurrent with the script, and none of the lines in the script wait for an answer. So it is perfectly possible for many messages to have been delivered to the actor before the actor decides to process any of them.

    It then comes down to how should an actor go through its mailbox. It can go through it as a queue. But it could also go randomly through it, which provides some interesting properties.

    My guess is that Scala 2.7.x, which was the version available when the book was written, used a queuing algorithm by default, while version 2.8.1 uses a random algorithm.

提交回复
热议问题