Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I like to use <code>scalaz.concurrent.Promise</code>. This example isn't exactly like the one in your question, but it gives you the idea.</p> <pre><code>object Async extends Application { import scalaz._ import Scalaz._ import concurrent._ import concurrent.strategy._ import java.util.concurrent.{ExecutorService, Executors} case class ResultA(resultb: ResultB, resulta: ResultC) case class ResultB() case class ResultC() run def run { implicit val executor: ExecutorService = Executors.newFixedThreadPool(8) import Executor.strategy val promiseA = doA println("waiting for results") val a: ResultA = promiseA.get println("got " + a) executor.shutdown } def doA(implicit s: Strategy[Unit]): Promise[ResultA] = { println("triggered A") val b = doB val c = doC for {bb &lt;- b; cc &lt;- c} yield ResultA(bb, cc) } def doB(implicit s: Strategy[Unit]): Promise[ResultB] = { println("triggered B") promise { Thread.sleep(1000); println("returning B"); ResultB() } } def doC(implicit s: Strategy[Unit]): Promise[ResultC] = { println("triggered C") promise { Thread.sleep(1000); println("returning C"); ResultC() } } } </code></pre> <p>Output:</p> <pre><code>triggered A triggered B triggered C waiting for results returning B returning C got ResultA(ResultB(),ResultC()) </code></pre> <p>You'll find an introduction to <a href="http://code.google.com/p/scalaz/" rel="nofollow noreferrer">Scalaz</a> concurrency in this <a href="http://twitter.com/runarorama/status/8573543228" rel="nofollow noreferrer">presentation</a> from Runar.</p> <p>This approach isn't as flexible as Actors, but composes better and can't deadlock.</p>
    singulars
    1. This table or related slice is empty.
    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.
    3. 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