title: nested asynchronous tasks (use CompletionStage in java)
body: <p>I use service (from library and i can't change it) that have 3 methods:</p>
  
  <pre><code>CompletionStage&lt;AData&gt; getAData(int id);
  CompletionStage&lt;BData&gt; getBData(int id);
  CompletionStage&lt;Path&gt; computePath(int id);
  </code></pre>
  
  <p>for my purpose i should get AData and BData, and then based on this values try compute some <code>Path</code>, and if i can't do it - use service call</p>
  
  <p>so my code now look like:</p>
  
  <pre><code> CompletionStage&lt;Path&gt; getPath(int id) {
        service.getAData(id).thenCombine(service.getBdata(id)), (a, b) -&gt; 
           {
               Path result = computePathLocaly(a, b);
               return result != null ? 
                              result : 
                              service.computePath(id).toCompletableFuture().join();
           }
  }
  </code></pre>
  
  <p>all work fine, but <code>toCompletableFuture().join()</code> looks awfully. 
  wrap <code>result</code> to <code>CompletionStage</code> and return <code>CompletionStage&lt;CompletionStage&lt;Path&gt;&gt;</code> - even worse...</p>
  
  <p>I'm belive that it's can be done more gracefully, but i can't realize how to... Please help.</p>