I have followed this tutorial: http://doc.akka.io/docs/akka/2.0/intro/getting-started-first-scala.html
Basically there is a Master actor which responds to these two messages:
def receive = {
case Calculate => {
//....
}
case Result(value) => {
//....
}
}
We send the message “Calculate” and after several “Result”s (from the slave actors) we have the correct calculation
Now I am inside an action of a play2 controller and I am using this:
val promise = (master ? Calculate)(10.seconds).mapTo[String].asPromise
Unfortunately (obviously) I get nothing because Calculate message does reply with a message to the sender.
I would like to somehow make the Akka Actor wait…. and when the computation is complete to send a message back to the sender.
But how?… Unless I am modelling it in the wrong way!
You should either
forwardthe message to the slaves (which keeps the same sender), or include the sender in the message to the slaves. For example:or
or
I’m not familiar with Play promises, but
?(ask) returns a AkkaFuture. If.asPromiseconverts an AkkaFutureto a PlayPromisethen you’re set.