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
- not make the Actor fail with a
MatchError
- 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.