title: Scala async vs. Java ForkJoinTask
body: <p>Some time ago I discovered the <a href="https://github.com/scala/async" rel="noreferrer">Scala Async Project</a>. The question is: what is so magical in this <code>async</code> blocks which can not be implemented via plain functions (without macro expansion)?</p>
  
  <p>Let's look at the first example from the introduction:</p>
  
  <pre><code>import ExecutionContext.Implicits.global
  import scala.async.Async.{async, await}
  
  val future = async {
      val f1 = async { ...; true }
      val f2 = async { ...; 42 }
      if (await(f1)) await(f2) else 0
  }
  </code></pre>
  
  <p>I do not see anything in the above example which can not be written in pure Java. This code does exactly the same thing:</p>
  
  <pre><code>import java.util.concurrent.*;
  import java.util.function.Supplier;
  
  // First define a helper method for creating async blocks:
  public static &lt;T&gt; ForkJoinTask&lt;T&gt; async(Supplier&lt;T&gt; supplier) {
      return new RecursiveTask&lt;T&gt;() {
          @Override
          protected T compute() {
              return supplier.get();
          }
      }.fork();
  }
  
  ForkJoinTask&lt;Integer&gt; future = ForkJoinPool.commonPool().submit(() -&gt; {
      ForkJoinTask&lt;Boolean&gt; f1 = async(() -&gt; true);
      ForkJoinTask&lt;Integer&gt; f2 = async(() -&gt; 42);
  
      if (f1.join()) {
          return f2.join();
      } else {
          return 42;
      }
  });
  </code></pre>
  
  <p>What can Scala <code>async</code> do that Java can't? Maybe in case of some more complex scenarios? What do I miss?</p>