Why is Actor.receive a partial function?

2019-07-04 23:16发布

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

标签: scala akka
2条回答
Ridiculous、
2楼-- · 2019-07-04 23:32

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.

查看更多
手持菜刀,她持情操
3楼-- · 2019-07-04 23:47

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.

查看更多
登录 后发表回答