title: Flawed Understanding of Futures in For Comprehension
body: <p>Most likely I'm not using the <code>For</code> comprehension appropriately but my question is relatively generic I think. I have two <code>Futures</code> created inside a Play Action.  </p>
  
  <ol>
  <li>The first calls my cache to get a value   </li>
  <li>The second then calls a web service (there is no dependency on the value from cache however)</li>
  </ol>
  
  <p>Even though I could instantiate these <code>Future</code>s outside the <code>for</code> to give them the opportunity to run in parallel, I want them in sequence because <strong>I only want the 2nd <code>Future</code> (web service call) to be created if the <code>value</code> was found in the cache.</strong></p>
  
  <pre><code>for {
          value &lt;- getValueFromCache   // Future[Option[String]]
  
          wsResponse &lt;- callWebService(value)   // Future[WSResponse]
  
   } yield wsResponse
  </code></pre>
  
  <p><strong>My Problem</strong><br>
  <strong>When I execute the above, and the <code>value</code> is Not found in the cache, the second Future (the web service call) is still created/executed - which I do Not want.</strong> </p>
  
  <p>My understanding of the <code>for</code> comprehension is that even if the second task is not directly dependant on the first, the second will only run if the first completed successfully.</p>
  
  <p>If the <code>value</code> is not found in the cache, <code>value = None</code>.<br>
  Is this why the 2nd <code>Future</code> still gets created/executed - because <code>None</code> is still considered a successful completion of the first <code>Future</code>?</p>
  
  <p>Under what circumstances will the 2nd <code>Future</code> not get created - if, and only if, the first <code>Future</code> completes with a <code>Exception</code>?</p>
  
  <p>I was considering using an <code>if 1st not complete properly then do not continue</code> type of statement but this still leaves my understanding of how <code>for</code> works with a big gap. </p>