title: Scala Future onComplete callback not executing immediately
body: <p>I have a Future[Future[Set[String]]. I flatmap it to return a Future[Set[String]]. I wait for infinity (I know this is bad) and then check if the Future is complete. It returns true. However, when I get the value returned by Future and try to add it to a Set, it doesn't add it. Statements at the end of the callback get printed first. When I return the Set from the method, it is always empty though the Future does return values. I have added comments as to explain the sequence of events happening. Please point me if I am doing something wrong! Thanks!</p>
  
  <pre><code>val googleXfpSegments = Set[String]()
  val customCriteriaFuture: Future[List[Long]] = getCustomCriteriaValueIds(lineItemPage.getResults())
  // getCustomCriteriaValues returns a Future[Set[String]]
  val criteriaValueList = customCriteriaFuture.flatMap(criteriaIdList =&gt; getCustomCriteriaValues(criteriaIdList.toSet))
  // I wait for infinite time
  Await.result(criteriaValueList, scala.concurrent.duration.Duration.Inf)
  log.info("Future Completed = " + criteriaValueList.isCompleted) // This returns true
  criteriaValueList onComplete {
      case Success(segmentNames) =&gt; {
          // This statement gets printed after the "TEST" value gets printed
          log.info("SegmentNameList = " + segmentNames.mkString(","))
          googleXfpSegments ++= segmentNames
          // This prints nothing which means the segmentNames is not getting added
          log.info("Google Segments = " + googleXfpSegments.mkString(",")) 
      }
      case Failure(error) =&gt; log.error("Error occurred ", error)
  }
  googleXfpSegments += "TEST"
  // This prints TEST
  log.info("Google Segments = " + googleXfpSegments.mkString(",")) 
  </code></pre>
  
  <p>Log output is shown below:</p>
  
  <pre><code>[info] [INFO] [2014-12-09 17:25:01,147] [service.GoogleXFPService] Future Completed = true 
  [info] [INFO] [2014-12-09 17:25:01,148] [service.GoogleXFPService] Google Segments = TEST 
  [info] [INFO] [2014-12-09 17:25:01,148] [service.GoogleXFPService] SegmentNameList = vt.cm,vt.cp,ex.qy,ex.ahe,cm.gannett_trav
  </code></pre>