Last active
April 19, 2018 09:23
-
-
Save nraychaudhuri/9381621 to your computer and use it in GitHub Desktop.
Revisions
-
nraychaudhuri revised this gist
Mar 6, 2014 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,10 @@ object Application extends Controller { val computeActor = Akka.system.actorOf(Props[BizActor]) def index = Action.async { //using Promise as a write handle for the response from actor. //we will use this promise to create a future (read handle) //which will be returned from this action. This future will complete //when the promise is successfully populated with value val p = Promise[String] val replyTo = Akka.system.actorOf(Props(new Actor { def receive = { @@ -21,6 +25,7 @@ object Application extends Controller { } })) computeActor.tell(msg = "do work for me", sender = replyTo) //transforming the actor response to Play result p.future.map(response => Ok(response)) } -
nraychaudhuri created this gist
Mar 6, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ package controllers import play.api.mvc._ import scala.concurrent._ import akka.actor.{Props, Actor} import play.api.Play.current import play.api.libs.concurrent.Akka import scala.concurrent.ExecutionContext.Implicits._ object Application extends Controller { val computeActor = Akka.system.actorOf(Props[BizActor]) def index = Action.async { val p = Promise[String] val replyTo = Akka.system.actorOf(Props(new Actor { def receive = { case reply: String => p.success(reply) context.stop(self) } })) computeActor.tell(msg = "do work for me", sender = replyTo) p.future.map(response => Ok(response)) } } class BizActor extends Actor { def receive = { case _ => sender ! "I am done with work" } }