title: How to interrupt asynchronous computations in Scala?
body: <p>I need to run two parallel computations and interrupt the first one when the second one finishes. Currently, I've implemented it using standard Java threads:</p>
  
  <pre><code>/**
   * Runs &lt;var&gt;sup&lt;/var&gt; in parallel with &lt;var&gt;main&lt;/var&gt;.
   * Terminate (interrupt) it when &lt;var&gt;main&lt;/var&gt; finishes.
   */
  def support[R](sup: =&gt; Unit, main: =&gt; R): R = {
    val supThread = new Thread {
      override def run = { sup };
    }
  
    supThread.start();
    try {
      main;
    } finally {
      supThread.interrupt();
    }
  }
  </code></pre>
  
  <p>Can the same behavior be achieved using Scala's concurrent library, without using <code>Thread</code>s explicitly?</p>