2016-04-11 66 views
0

我使用噴霧服務器,我有一個工作得到落實,這是我想延長,但第二個不工作: 首先,工作落實:斯卡拉演員接受的定義與噴霧

def receive = runRoutes(routes) 

第二版:

def receive = { 
    case GetRoutes => sender() ! getRoute ~ deleteRoute ~ postRoute ~ patchRoute 
    case x => runRoute(getRoute ~ deleteRoute ~ postRoute ~ patchRoute) 
} 

runRoute的類型是Actor.Receive

感謝

回答

2

你有實際呼叫的runRoute如果你寫的,你在第二個例子做:

val run = runRoute(getRoute) // takes a number of implicit params to construct the route 
def receive = { 
    case x => run(x) 
} 

取而代之的是不過我建議來組成Actor.Receive功能使用此模式:

val special: Actor.Receive = { case GetRoutes => sender() ! getRoute ! ... } 
def receive: Actor.Receive = special orElse runRoute(getRoute ~ ...) 

您可以閱讀更多關於鏈接PartialFunction s on f rom此博客文章,例如:http://daily-scala.blogspot.com/2010/02/chaining-partial-functions-with-orelse.html

+0

非常有幫助,清晰和信息。完美的作品。非常感謝 – mani