title: Scala waiting for sequence of futures
body: <p>I was hoping code like follows would wait for both futures, but it does not. </p>
  
  <pre><code>object Fiddle {
    val f1 = Future {
      throw new Throwable("baaa") // emulating a future that bumped into an exception
    }
  
    val f2 = Future {
      Thread.sleep(3000L) // emulating a future that takes a bit longer to complete
      2
    }
  
    val lf = List(f1, f2) // in the general case, this would be a dynamically sized list
  
    val seq = Future.sequence(lf) 
  
    seq.onComplete {
      _ =&gt; lf.foreach(f =&gt; println(f.isCompleted))
    }
  }
  
  val a = FuturesSequence
  </code></pre>
  
  <p>I assumed <code>seq.onComplete</code> would wait for them all to complete before completing itself, but not so; it results in:</p>
  
  <pre><code>true
  false
  </code></pre>
  
  <p><code>.sequence</code> was a bit hard to follow in the source of scala.concurrent.Future, I wonder how I would implement a parallel that waits for all original futures of a (dynamically sized) sequence, or what might be the problem here.</p>
  
  <p><em>Edit:</em> A related question: <a href="https://worldbuilding.stackexchange.com/questions/12348/how-do-you-prove-youre-from-the-future">https://worldbuilding.stackexchange.com/questions/12348/how-do-you-prove-youre-from-the-future</a> :)</p>