In my actor I have two requests at different addresses like this:
http.singleRequest(HttpRequest(uri = encodedUri).addHeader(Accept(MediaTypes.`application/json`)))
I need that these two requests return both a value. As normal futures I would expect something like this:
val response: Future[SomeData] = for {
r1 <- firstRequest
r2 <- secondRequest
} yield {
// merge the results of these two responses
}
response onComplete {
case Success(body) => sndr ! Something(body)
case Failure(message) => BadRequest(message.toString)
}
In this part of the documentation:
http://doc.akka.io/docs/akka/2.4/scala/http/client-side/request-level.html
It is suggested to use pipeTo to self to manage the single request, instead of using native onComplete/map/etc.
How can I apply that for multiple requests like in my case, where I need to wait for 2 or more to be completed?