Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use <a href="http://doc.akka.io/docs/akka/snapshot/scala/futures.html" rel="nofollow"><code>after</code></a> from <code>akka</code> instead of blocking <code>Await.result</code>:</p> <pre><code>val timeout = akka.pattern.after(FiniteDuration(60000, MILLISECONDS), using = system.scheduler){ Future.successful(None) } val resFuture = for { result1 &lt;- Future firstCompletedOf Seq(future1.map{Some(_)}, timeout) result2 &lt;- Future firstCompletedOf Seq(future2.map{Some(_)}, timeout) } yield (result1, result2) val result = resFuture map { case (Some(r1), Some(r2)) =&gt; Merge(r1, r2) case (Some(r1), None) =&gt; PartialResult1(r1) case (None, Some(r2)) =&gt; PartialResult2(r2) case _ =&gt; EmptyResult } </code></pre> <p>In this case <code>resFuture</code> will be completed in 60 seconds and you can process partial result. Also you don't need <code>Await</code> in <code>Play</code> - you could use <a href="http://www.playframework.com/documentation/2.3-SNAPSHOT/ScalaAsync" rel="nofollow"><code>Async</code></a>.</p> <p>In case you have many equivalent futures of the same type you could use it like this:</p> <pre><code>val futures: Seq[Future[Int]] = ??? val futureWithTimeout = futures.map{ f =&gt; Future firstCompletedOf Seq(f.map{Some(_)}, timeout) } val result: Future[Seq[Option[Int]]] = Future.sequence(futureWithTimeout) // In case you need to know index of completed or not completed future val indexedResults = result.zipWithIndex // In case you just need only completed results val completedResults: Future[Seq[Option[Int]]] = result.map{_.flatten} </code></pre> <p>Types here are only for illustration.</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. 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.
 

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