title: Twitter's Future.collect not working concurrently (Scala)
body: <p>Coming from a node.js background, I am new to Scala and I tried using Twitter's Future.collect to perform some simple concurrent operations. But my code shows sequential behavior rather than concurrent behavior. What am I doing wrong?</p>
  
  <p>Here's my code,</p>
  
  <pre><code>import com.twitter.util.Future
  
  def waitForSeconds(seconds: Int, container:String): Future[String]  = Future[String] {
    Thread.sleep(seconds*1000)
    println(container + ": done waiting for " + seconds + " seconds")
    container + " :done waiting for " + seconds + " seconds"
  }
  
  def mainFunction:String = {
    val allTasks = Future.collect(Seq(waitForSeconds(1, "All"), waitForSeconds(3, "All"), waitForSeconds(2, "All")))
    val singleTask = waitForSeconds(1, "Single")
  
    allTasks onSuccess  { res =&gt;
      println("All tasks succeeded with result " + res)
    }
  
    singleTask onSuccess { res =&gt;
      println("Single task succeeded with result " + res)
    }
  
    "Function Complete"
  }
  
  println(mainFunction)
  </code></pre>
  
  <p>and this is the output I get,</p>
  
  <pre><code>All: done waiting for 1 seconds
  All: done waiting for 3 seconds
  All: done waiting for 2 seconds
  Single: done waiting for 1 seconds
  All tasks succeeded with result ArraySeq(All :done waiting for 1 seconds, All :done waiting for 3 seconds, All :done waiting for 2 seconds)
  Single task succeeded with result Single :done waiting for 1 seconds
  Function Complete
  </code></pre>
  
  <p>The output I expect is,</p>
  
  <pre><code>All: done waiting for 1 seconds
  Single: done waiting for 1 seconds
  All: done waiting for 2 seconds
  All: done waiting for 3 seconds
  All tasks succeeded with result ArraySeq(All :done waiting for 1 seconds, All :done waiting for 3 seconds, All :done waiting for 2 seconds)
  Single task succeeded with result Single :done waiting for 1 seconds
  Function Complete
  </code></pre>