@Override
                            public void completed(final AsyncConnectionEndpoint connectionEndpoint) {
                                final InternalAsyncClientEndpoint endpoint = new InternalAsyncClientEndpoint(connectionEndpoint);
                                final AtomicInteger messageCountDown = new AtomicInteger(2);
                                final AsyncClientExchangeHandler internalExchangeHandler = new AsyncClientExchangeHandler() {

                                    @Override
                                    public void releaseResources() {
                                        try {
                                            exchangeHandler.releaseResources();
                                        } finally {
                                            endpoint.releaseAndDiscard();
                                        }
                                    }

                                    @Override
                                    public void failed(final Exception cause) {
                                        try {
                                            exchangeHandler.failed(cause);
                                        } finally {
                                            endpoint.releaseAndDiscard();
                                        }
                                    }

                                    @Override
                                    public void cancel() {
                                        failed(new RequestFailedException("Request aborted"));
                                    }

                                    @Override
                                    public void produceRequest(
                                            final RequestChannel channel,
                                            final HttpContext context1) throws HttpException, IOException {
                                        channel.sendRequest(request, entityDetails, context1);
                                        if (entityDetails == null) {
                                            messageCountDown.decrementAndGet();
                                        }
                                    }

                                    @Override
                                    public int available() {
                                        return exchangeHandler.available();
                                    }

                                    @Override
                                    public void produce(final DataStreamChannel channel) throws IOException {
                                        exchangeHandler.produce(new DataStreamChannel() {

                                            @Override
                                            public void requestOutput() {
                                                channel.requestOutput();
                                            }

                                            @Override
                                            public int write(final ByteBuffer src) throws IOException {
                                                return channel.write(src);
                                            }

                                            @Override
                                            public void endStream(final List<? extends Header> trailers) throws IOException {
                                                channel.endStream(trailers);
                                                if (messageCountDown.decrementAndGet() <= 0) {
                                                    endpoint.releaseAndReuse();
                                                }
                                            }

                                            @Override
                                            public void endStream() throws IOException {
                                                channel.endStream();
                                                if (messageCountDown.decrementAndGet() <= 0) {
                                                    endpoint.releaseAndReuse();
                                                }
                                            }

                                        });
                                    }

                                    @Override
                                    public void consumeInformation(
                                            final HttpResponse response,
                                            final HttpContext context1) throws HttpException, IOException {
                                        exchangeHandler.consumeInformation(response, context1);
                                    }

                                    @Override
                                    public void consumeResponse(
                                            final HttpResponse response,
                                            final EntityDetails entityDetails,
                                            final HttpContext context1) throws HttpException, IOException {
                                        exchangeHandler.consumeResponse(response, entityDetails, context1);
                                        if (response.getCode() >= HttpStatus.SC_CLIENT_ERROR) {
                                            messageCountDown.decrementAndGet();
                                        }
                                        if (entityDetails == null) {
                                            if (messageCountDown.decrementAndGet() <= 0) {
                                                endpoint.releaseAndReuse();
                                            }
                                        }
                                    }

                                    @Override
                                    public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
                                        exchangeHandler.updateCapacity(capacityChannel);
                                    }

                                    @Override
                                    public void consume(final ByteBuffer src) throws IOException {
                                        exchangeHandler.consume(src);
                                    }

                                    @Override
                                    public void streamEnd(final List<? extends Header> trailers) throws HttpException, IOException {
                                        if (messageCountDown.decrementAndGet() <= 0) {
                                            endpoint.releaseAndReuse();
                                        }
                                        exchangeHandler.streamEnd(trailers);
                                    }

                                };
                                if (responseTimeout != null) {
                                    endpoint.setSocketTimeout(responseTimeout);
                                }
                                endpoint.execute(internalExchangeHandler, pushHandlerFactory, clientContext);
                            }
Minimal implementation of {@link CloseableHttpAsyncClient}. This client is
optimized for HTTP/1.1 and HTTP/2 message transport and does not support
advanced HTTP protocol functionality such as request execution via a proxy,
state management, authentication and request redirects.
<p>
Concurrent message exchanges executed by this client will get assigned to
separate connections leased from the connection pool.
</p>

@since 5.0
httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java