【发布时间】:2015-07-12 04:37:23
【问题描述】:
给定以下喷涂代码:
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 指令中。
文档解释说 detach 将:execute the inner route inside a future.
从性能的角度来看,使用(或不使用)detach 有什么意义?
我看了这个相关的answer,但是重点是如何使用detach。
【问题讨论】: