On 05/18/15 10:31, Andrew Gaydenko wrote:
On Monday, May 18, 2015 at 7:51:31 PM UTC+3, Michael Frank wrote:
How about piping the result of the future back to actor1, then
send the result to actor2? you can prune the completed future in
actor1 when it receives the result.
Michael, how does actor1 discover that future returned result is
connected to?
i usually solve this by map()ing the future to some request id that i
generate. for example (written on the spot, may not compile):
class Actor1(externalService: MyService, actor2: ActorRef) extends Actor {
import Actor1.RequestResult
var inFlight: Map[Long,Future] = Map.empty
var sequenceNr: Long = 0
def receive = {
case GotSomeExternalRequest(params) =>
val requestId = sequenceNr
sequenceNr = sequenceNr + 1
val future = externalService.asyncRequest().map(result =>
RequestResult(requestId, result)).pipeTo(self)
inFlight = inFlight + (requestId -> future)
case RequestResult(requestId, result) =>
inFlight = inFlight - requestId
actor2 ! result
}
}
object Actor1 {
case class RequestResult(requestId: Long, result: Result)
}
-Michael
--
Read the docs: http://akka.io/docs/
Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.