title: Understanding CompletableFuture::runAsync
body: <p>I just read <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html#runAsync-java.lang.Runnable-java.util.concurrent.Executor-" rel="noreferrer"><strong><em>the documentation</em></strong></a> about <code>CompletableFuture::runAsync</code> and was pretty confused by the explanation. Here is what's written there:</p>
  
  <blockquote>
    <p>Returns a new <code>CompletableFuture</code> that is asynchronously completed by a
    task running in the given executor after it runs the given action.</p>
  </blockquote>
  
  <p>As far as I understand it, <code>CompletableFuture</code> looks like <code>Future</code> with that it can "register" some sort of callbacks and invoke them implicitly once a given action is finished. </p>
  
  <p>Taking that into account, let's consider the following code:</p>
  
  <pre><code>ExecutorService threadsPool;
  Runnable r;
  //...
  CompletableFuture.runAsync(r, threadsPool);
  </code></pre>
  
  <p>In this code we register the <code>Runnable</code> to be executed asynchronously in the given <code>ThreadPool</code>. </p>
  
  <p>But what does it mean <strong><em><code>CompletableFuture</code> that is asynchronously completed by a task</em></strong>. How can the task make the <code>CompletableFuture</code> become completed... ? It doesn't make much sense to me.</p>