title: How to cancel Java 8 completable future?
body: <p>I am playing with Java 8 completable futures. I have the following code:</p>
  
  <pre><code>CountDownLatch waitLatch = new CountDownLatch(1);
  
  CompletableFuture&lt;?&gt; future = CompletableFuture.runAsync(() -&gt; {
      try {
          System.out.println("Wait");
          waitLatch.await(); //cancel should interrupt
          System.out.println("Done");
      } catch (InterruptedException e) {
          System.out.println("Interrupted");
          throw new RuntimeException(e);
      }
  });
  
  sleep(10); //give it some time to start (ugly, but works)
  future.cancel(true);
  System.out.println("Cancel called");
  
  assertTrue(future.isCancelled());
  
  assertTrue(future.isDone());
  sleep(100); //give it some time to finish
  </code></pre>
  
  <p>Using runAsync I schedule execution of a code that waits on a latch. Next I cancel the future, expecting an interrupted exception to be thrown inside. But it seems that the thread remains blocked on the await call and the InterruptedException is never thrown even though the future is canceled (assertions pass). An equivalent code using ExecutorService works as expected. Is it a bug in the CompletableFuture or in my example?</p>