Details
-
Improvement
-
Status: Resolved
-
Trivial
-
Resolution: Fixed
-
5.0
-
None
Description
The source code for CloseableHttpAsyncClient#execute(SimpleHttpRequest, HttpContext, FutureCallback) looks like this:
public final Future<SimpleHttpResponse> execute( final SimpleHttpRequest request, final HttpContext context, final FutureCallback<SimpleHttpResponse> callback) { Args.notNull(request, "Request"); final BasicFuture<SimpleHttpResponse> future = new BasicFuture<>(callback); execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), context, new FutureCallback<SimpleHttpResponse>() { @Override public void completed(final SimpleHttpResponse response) { future.completed(response); } @Override public void failed(final Exception ex) { future.failed(ex); } @Override public void cancelled() { future.cancel(true); } }); return future; }
To me this looks more complicated than it needs to be. I think it can be replaced with just:
public final Future<SimpleHttpResponse> execute( final SimpleHttpRequest request, final HttpContext context, final FutureCallback<SimpleHttpResponse> callback) { Args.notNull(request, "Request"); return execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), context, callback); }