title: Scala future sequence and timeout handling
body: <p>There are some good hints how to combine futures <a href="https://stackoverflow.com/questions/17466889/run-multiple-futures-in-parallel-return-default-value-on-timeout">with timeouts</a>.
  However I'm curious how to do this with <strong>Future sequence sequenceOfFutures</strong></p>
  
  <p>My first approach looks like this</p>
  
  <pre><code>import scala.concurrent._
  import scala.concurrent.duration._
  import scala.concurrent.ExecutionContext.Implicits._
  
  object FutureSequenceScala extends App {
    println("Creating futureList")
  
    val timeout = 2 seconds
    val futures = List(1000, 1500, 1200, 800, 2000) map { ms =&gt;
      val f = future {
        Thread sleep ms
        ms toString
      }
      Future firstCompletedOf Seq(f, fallback(timeout))
    }
  
    println("Creating waitinglist")
    val waitingList = Future sequence futures
    println("Created")
  
    val results = Await result (waitingList, timeout * futures.size)
    println(results)
  
    def fallback(timeout: Duration) = future {
      Thread sleep (timeout toMillis)
      "-1"
    }
  }
  </code></pre>
  
  <p>Is there a better way to handle timeouts in a sequence of futures or is this a valid solution?</p>