Why is Actor.receive a partial function?

两盒软妹~` 提交于 2020-01-03 19:41:50

问题


Why is Actor.receive a partial function? I can always have a regular function with match expression instead of it.


回答1:


It is a PartialFunction to capture the possibility of a message being handled or unhandled by the Actor. An unhandled message will

  1. not make the Actor fail with a MatchError
  2. spawn an UnhandledMessage event to the event stream

More info here.




回答2:


One reason would be that the partial function has isDefinedAt method, which allows Akka to check if the message can be handled without catching the scala.MatchError exception from user's code.



来源:https://stackoverflow.com/questions/41260676/why-is-actor-receive-a-partial-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!