How do I get a CompletableFuture<T> from an Async Http Client request?
<p>On <a href="https://github.com/AsyncHttpClient/async-http-client" rel="noreferrer">Async Http Client documentation</a> I see how to get a <code>Future&lt;Response&gt;</code> as the result of an asynchronous HTTP Get request simply doing, for example: </p>

<pre><code>AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();
Future&lt;Response&gt; f = asyncHttpClient
      .prepareGet("http://api.football-data.org/v1/soccerseasons/398")
      .execute();
Response r = f.get();
</code></pre>

<p>However, for convenience I would like to get a <code>CompletableFuture&lt;T&gt;</code> instead, for which I could apply a continuation that converts the result in something else, for instance deserializing the response content from Json into a Java object (e.g. <a href="https://gist.github.com/fmcarvalho/307525062873c83c82ad662a2c7a3f74" rel="noreferrer">SoccerSeason.java</a>). This is what I would like to do:</p>

<pre><code>AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();
CompletableFuture&lt;Response&gt; f = asyncHttpClient
     .prepareGet("http://api.football-data.org/v1/soccerseasons/398")
     .execute();
f
     .thenApply(r -&gt; gson.fromJson(r.getResponseBody(), SoccerSeason.class))
     .thenAccept(System.out::println);
</code></pre>

<p>According to <a href="https://github.com/AsyncHttpClient/async-http-client" rel="noreferrer">Async Http Client documentation</a> the only way to do this is through an <code>AsyncCompletionHandler&lt;T&gt;</code> object and using a promise. So I built an <a href="https://gist.github.com/fmcarvalho/fcfe91effc495bae5fe1110b13b5c26d" rel="noreferrer">auxiliary method</a> to that end: </p>

<pre><code>CompletableFuture&lt;Response&gt; getDataAsync(String path){
    CompletableFuture&lt;Response&gt; promise = new CompletableFuture&lt;&gt;();
    asyncHttpClient
            .prepareGet(path)
            .execute(new AsyncCompletionHandler&lt;Response&gt;() {
                @Override
                public Response onCompleted(Response response) throws Exception {
                    promise.complete(response);
                    return response;
                }
                @Override
                public void onThrowable(Throwable t) {
                    promise.completeExceptionally(t);
                }
            });
    return promise;
}
</code></pre>

<p>With this utility method I can rewrite the previous example just doing:</p>

<pre><code>getDataAsync("http://api.football-data.org/v1/soccerseasons/398")
    .thenApply(r -&gt; gson.fromJson(r.getResponseBody(), SoccerSeason.class))
    .thenAccept(System.out::println);
</code></pre>

<p>Is there any better way of getting a <code>CompletableFuture&lt;T&gt;</code> from an Async Http Client request?</p>