Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not sure that is what you are looking for, but there is quite a simple solution in the comet-clock sample, that you can adapt to use AKKA actors. It uses an infinite iframe instead of long polling. I have used an adapted version for a more complex application doing multiple DB calls and long computation in AKKA actors and it works fine.</p> <pre><code> def enum = Action { //get your actor val myActorRef = Akka.system.actorOf(Props[TestActor]) //do some query to your DB here. Promise.timeout is to simulate a blocking call def getDatabaseItem(id: Int): Promise[String] = { Promise.timeout("test", 10 milliseconds) } //test iterator, you will want something smarter here val items1 = 1 to 10 toIterator // this is a very simple enumerator that takes ints from an existing iterator (for an http request parameters for instance) and do some computations def myEnum(it: Iterator[Int]): Enumerator[String] = Enumerator.fromCallback[String] { () =&gt; if (!items1.hasNext) Promise.pure[Option[String]](None) //we are done with our computations else { // get the next int, query the database and compose the promise with a further query to the AKKA actor getDatabaseItem(items1.next).flatMap { dbValue =&gt; implicit val timeout = new Timeout(10 milliseconds) val future = (myActorRef ? dbValue) mapTo manifest[String] // here we convert the AKKA actor to the right Promise[Option] output future.map(v =&gt; Some(v)).asPromise } } } // finally we stream the result to the infinite iframe. // console.log is the javascript callback, you will want something more interesting. Ok.stream(myEnum(items1) &amp;&gt; Comet(callback = "console.log")) } </code></pre> <p>Note that this fromCallback doesn't allow you to combine enumerators with "andThen", there is in the trunk version of play2 a generateM method that might be more appropriate if you want to use combinations.</p> <p>It's not long polling, but it works fine.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload