title: Break the flow of CompletableFuture
body: <p>I have certain flow that runs async using the <code>CompletableFuture</code>, e.g.:</p>
  
  <pre><code>foo(...)
          .thenAccept(aaa -&gt; {
              if (aaa == null) {
                   break!
              }
              else {
                ...
              }
          })
          .thenApply(aaa -&gt; {
             ...
          })
          .thenApply(...
  </code></pre>
  
  <p>So if my <code>foo()</code> returns <code>null</code> (in a future) I need to break very soon, otherwise, the flow continue.</p>
  
  <p>For now I have to check for <code>null</code> all the way, in every future block; but that is ugly.</p>
  
  <p>Would this be possible with <code>CompletableFuture</code>?</p>
  
  <h3>EDIT</h3>
  
  <p>With <code>CompletableFuture</code> you can define your flow of async tasks, that are executed one after the other. For example, you may say:</p>
  
  <blockquote>
    <p>Do A, and when A finishes, do B, and then do C...</p>
  </blockquote>
  
  <p>My question is about breaking this flow and saying:</p>
  
  <blockquote>
    <p>Do A, but if result is null break; otherwise do B, and then do C...</p>
  </blockquote>
  
  <p>This is what I meant by 'breaking the flow`.</p>