Cancellation of CompletableFuture controlled by ExecutorService
<p>I have an <code>ExecutorService</code> which forwards the computed data to a <code>CompletableFuture</code>:</p>

<pre><code>class DataRetriever {
    private final ExecutorService service = ...;

    public CompletableFuture&lt;Data&gt; retrieve() {
        final CompletableFuture&lt;Data&gt; future = new CompletableFuture&lt;&gt;();

        service.execute(() -&gt; {
            final Data data = ... fetch data ...
            future.complete(data);
        });
        return future;
    }
}
</code></pre>

<p>I want the client/user to be able to cancel the task:</p>

<pre><code>final DataRetriever retriever = new DataRetriever();
final CompletableFuture&lt;Data&gt; future = retriever().retrieve();

future.cancel(true);
</code></pre>

<p>This does not work, as this cancels the outer <code>CompletableFuture</code>, but not the inner future as scheduled in the executor service.</p>

<p>Is it somehow possible to propagate <code>cancel()</code> on the outer future to the inner future?</p>