[英]Scala Actor receive definition with Spray
I am using spray server, and I have a working receive implementation, which I wanted to extend, but the second one is not working: First, working implementation: 我正在使用Spray服务器,并且我有一个要扩展的有效的接收实现,但是第二个不起作用:首先,有效的实现:
def receive = runRoutes(routes)
Second version: 第二版:
def receive = {
case GetRoutes => sender() ! getRoute ~ deleteRoute ~ postRoute ~ patchRoute
case x => runRoute(getRoute ~ deleteRoute ~ postRoute ~ patchRoute)
}
runRoute
is of type Actor.Receive
. runRoute
的类型为Actor.Receive
。
Thanks 谢谢
You have to actually call the runRoute if you write it as you do in the 2nd example: 如果像在第二个示例中那样编写,则必须实际调用 runRoute:
val run = runRoute(getRoute) // takes a number of implicit params to construct the route
def receive = {
case x => run(x)
}
Instead of that however I'd suggest to compose the Actor.Receive
functions using this pattern: 与其相反,我建议使用以下模式组成Actor.Receive
函数:
val special: Actor.Receive = { case GetRoutes => sender() ! getRoute ! ... }
def receive: Actor.Receive = special orElse runRoute(getRoute ~ ...)
You can read more about chaining PartialFunction
s on from this blog post for example: http://daily-scala.blogspot.com/2010/02/chaining-partial-functions-with-orelse.html 您可以从此博客文章中获取有关链接PartialFunction
的更多信息,例如: http : PartialFunction
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.