鉴于以下喷码:喷雾的`detach`指令
object Main extends App with SimpleRoutingApp {
implicit val system = ActorSystem("my-system")
val pipeline: HttpRequest => Future[String] = sendReceive ~> unmarshal[String]
startServer(interface = "localhost", port = 8080) {
path("go") {
get {
detach() {
complete {
val req = Post("http://www.google.com") ~> addHeader("Foo", "bar")
pipeline(req).recoverWith[String]{ case _ => Future { "error!" } }
}
}
}
}
}
}
我把complete
功能detach指令中。
该文档解释分离将:execute the inner route inside a future.
什么是使用(或不)的意义detach
- 从性能观点?
我看了这个相关的answer,但它专注于如何使用detach。
试图理解你的前几句话 - 不会使用'detach'并在'route'内部调用'Await.result'结果一次只处理一个HTTP请求,即同时由web应用程序处理? –
https://groups.google.com/forum/#!topic/spray-user/ml3auuHoq_4 –
这里也要回答:是的,的确如此。如果没有使用异步指令,阻塞路由结构将阻止异步路由处理。 – jrudolph