title: scala's for yield comprehension used with Future. How to wait until future has returned?
body: <p>I have a function which provides a Context:</p>
  
  <pre><code>def buildContext(s:String)(request:RequestHeader):Future[Granite.Context] = {
      .... // returns a Future[Granite.Context]
  }
  </code></pre>
  
  <p>I then have another function which uses a Context to return an Option[Library.Document]:</p>
  
  <pre><code>def getDocument(tag: String):Option[Library.Document] = {
     val fakeRequest = play.api.test.FakeRequest().withHeaders(CONTENT_TYPE -&gt; "application/json")
  
     val context = buildContext(tag)(fakeRequest)
  
     val maybeDoc = context.getDocument //getDocument is defined on Granite.Context to return an Option[Library.Document]
  
  }
  </code></pre>
  
  <p>How would this code take into account if the Future has returned or not? I have seen for/yield used to wait for the return but I always assumed that a for/yield just flatmaps things together and has nothing really to do with waiting for Futures to return. I'm kinda stuck here and don't really no the correct question to ask!</p>