title: Scala's Future and ExecutionContext Execution
body: <p>Let's say I have the following set of code that does something in a Future:</p>
  
  <pre><code>1 to 10 foreach {
    case x =&gt; Future { x + x }
  }
  </code></pre>
  
  <p>Assuming that I give the default ExecutionContext to this piece of code, I know what happens in the background, but what I want to know is how is the handling of the Future actually done? I mean there should be some thread or a set of threads that should potentially be waiting for the Future to finish? Are these threads blocked? blocked in the sense where they are literally waiting for the Future to finish?</p>
  
  <p>Now in the following scenario:</p>
  
  <pre><code>val x: Future[MyType] = finishInSomeFuture()
  </code></pre>
  
  <p>Assuming that x has a timeout that I can call like this:</p>
  
  <pre><code>Future {
    blocking {
      x.get(3, TimeOut.SECONDS)
    }
  } 
  </code></pre>
  
  <p>Am I really blocking? Is there a better way to timeout asynchronously?</p>
  
  <p>EDIT: How different or how better is the following Timeout better than the blocking context that I defined above?</p>
  
  <pre><code>object TimeoutFuture {
    def apply[A](timeout: FiniteDuration)(block: =&gt; A): Future[A] = {
  
      val prom = promise[A]
  
      // timeout logic
      Akka.system.scheduler.scheduleOnce(timeout) {
        prom tryFailure new java.util.concurrent.TimeoutException
      }
  
      // business logic
      Future { 
        prom success block
      }
  
      prom.future
    } 
  }
  </code></pre>