Given the following Spray code:
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!" } }
}
}
}
}
}
}
I put the complete
function within the detach directive.
The docs explain that detach will: execute the inner route inside a future.
What's the significance of using (or not) detach
- from a performance perspective?
I looked at this related answer, but it focuses on how to use detach.