title: Scala getting rid of nested futures
body: <p>Could You please help me write it in a better way:</p>
  
  <pre><code>Future {
      Thread sleep 200
      5
  } onComplete{
      case Success(e) =&gt; Future {
          doSomething(e)
          Thread sleep 200
          6
      } onComplete {
          case Success(e) =&gt;
              Future {
                  doSomething(e)
                  Thread sleep 200
              } onComplete {
                  case Success(_) =&gt; println("finished")
                  case Failure(e) =&gt; e.printStackTrace()
              }
          case Failure(e) =&gt; e.printStackTrace()
      }
  
      case Failure(e) =&gt; e.printStackTrace()
  }
  </code></pre>
  
  <p>Now the code looks bad, and if I added more futures this way it would become even worse... This is obviously an example to show the problem, so I would appreciate mentioning wider context. </p>
  
  <p><strong>@update</strong> If it is not clear enough, I will try to clarify. I have three futures, and want to execute the first, when it finishes execute the second, when it finishes - the third. The second future uses result of the first, and the third uses result of the second one. If one of futures fail, stack trace is printed and call sequence breaks. This is what I wanted to show in the code above, and I want to achieve it in better, non-nesting way, if possible.</p>
  
  <p><strong>@update 2</strong> It would also be great if I would handle failure of each future separately</p>