I have a .net class which makes a HTTP Request to a controller in play but my controller has to make the request wait and after some time i have to make response to the request . I tried using Promise but can’t figure out how to achieve this need help to solve this…
Thanks in advance
Awaiting is generally not the best idea. What you probably want to do in this instance is create an Akka actor that gets ping’d by the Scheduler every so often. When it receives that ping message it would check if the condition you’re looking for exists and would notify all the actor-refs that registered interest in that event.
When you send a message to an akka actor via the ask pattern, the sender for that message is an actor backing the Future which is fulfilled once that backing actor is sent a message.
Play 2.0 has a simple way of turning an Akka Future into a Play Promise. And there you have it, asynchronous programming with Akka and Play!
So in summary, your Actor needs to react to two messages:
RegisterListener
Ping
RegisterListener is the message you send using the ask pattern, The actor will need to retain a reference to the sender of that listener so that it can be notified when the condition is fulfilled.