Skip to content

Commit bbbb2b1

Browse files
committed
Cleanup removal of waitForAsync()
1 parent d970136 commit bbbb2b1

File tree

5 files changed

+3
-37
lines changed

5 files changed

+3
-37
lines changed

client/src/main/java/io/avaje/http/client/DHttpClientContext.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import java.util.List;
1212
import java.util.Map;
1313
import java.util.concurrent.CompletableFuture;
14-
import java.util.concurrent.atomic.AtomicLong;
1514
import java.util.concurrent.atomic.AtomicReference;
16-
import java.util.concurrent.locks.LockSupport;
1715

1816
class DHttpClientContext implements HttpClientContext {
1917

@@ -33,7 +31,6 @@ class DHttpClientContext implements HttpClientContext {
3331
private final boolean withAuthToken;
3432
private final AuthTokenProvider authTokenProvider;
3533
private final AtomicReference<AuthToken> tokenRef = new AtomicReference<>();
36-
private final AtomicLong activeAsync = new AtomicLong();
3734
private int loggingMaxBody = 1_000;
3835

3936
DHttpClientContext(HttpClient httpClient, String baseUrl, Duration requestTimeout, BodyAdapter bodyAdapter, RetryHandler retryHandler, RequestListener requestListener, AuthTokenProvider authTokenProvider, RequestIntercept intercept) {
@@ -176,7 +173,6 @@ <T> HttpResponse<T> send(HttpRequest.Builder requestBuilder, HttpResponse.BodyHa
176173
}
177174

178175
<T> CompletableFuture<HttpResponse<T>> sendAsync(HttpRequest.Builder requestBuilder, HttpResponse.BodyHandler<T> bodyHandler) {
179-
activeAsync.incrementAndGet();
180176
return httpClient.sendAsync(requestBuilder.build(), bodyHandler);
181177
}
182178

@@ -196,28 +192,13 @@ <T> List<T> readList(Class<T> cls, BodyContent content) {
196192
return bodyAdapter.listReader(cls).read(content);
197193
}
198194

199-
@Override
200-
public boolean waitForAsync(long millis) {
201-
final long until = System.currentTimeMillis() + millis;
202-
do {
203-
if (activeAsync.get() <= 0) {
204-
return true;
205-
}
206-
LockSupport.parkNanos(10_000_000);
207-
} while (System.currentTimeMillis() < until);
208-
return false;
209-
}
210-
211195
void afterResponse(DHttpClientRequest request) {
212196
if (requestListener != null) {
213197
requestListener.response(request.listenerEvent());
214198
}
215199
if (requestIntercept != null) {
216200
requestIntercept.afterResponse(request.response(), request);
217201
}
218-
if (request.startAsyncNanos > 0) {
219-
activeAsync.decrementAndGet();
220-
}
221202
}
222203

223204
void beforeRequest(DHttpClientRequest request) {

client/src/main/java/io/avaje/http/client/DHttpClientRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DHttpClientRequest implements HttpClientRequest, HttpClientResponse {
5050
private boolean loggableResponseBody;
5151
private boolean skipAuthToken;
5252
private boolean suppressLogging;
53-
protected long startAsyncNanos;
53+
private long startAsyncNanos;
5454
private String label;
5555
private Map<String, Object> customAttributes;
5656

client/src/main/java/io/avaje/http/client/HttpClientContext.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ static HttpClientContext.Builder newBuilder() {
115115
*/
116116
byte[] decodeContent(String encoding, byte[] content);
117117

118-
/**
119-
* Wait for any submitted async requests with a given maximum wait time.
120-
*
121-
* @param maxWaitMillis The maximum time to wait in milliseconds
122-
* @return True if waiting was successful or false if there are still async requests that have not yet come back for completion.
123-
*/
124-
boolean waitForAsync(long maxWaitMillis);
125-
126118
/**
127119
* Builds the HttpClientContext.
128120
*

client/src/test/java/io/avaje/http/client/AsyncTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ void waitForAsync() {
3030
List<String> lines = hres.body().collect(Collectors.toList());
3131
assertThat(lines).hasSize(4);
3232
assertThat(lines.get(0)).contains("{\"id\":1, \"name\":\"one\"}");
33-
});
33+
}).join();
3434

35-
assertThat(flag).isFalse();
36-
assertThat(clientContext.waitForAsync(1_000)).isTrue();
3735
assertThat(flag).isTrue();
3836
}
3937

client/src/test/java/org/example/github/GithubTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ void test() {
3535
.thenAccept(res -> {
3636
System.out.println("RES: " + res.statusCode());
3737
System.out.println("BODY: " + res.body().substring(0, 150) + "...");
38-
});
39-
40-
long st = System.currentTimeMillis();
41-
System.out.println("waitForAsync");
42-
boolean waitSuccess = clientContext.waitForAsync(2_000);
43-
System.out.println("waitForAsync waitSuccess:" + waitSuccess + " waitMillis: " + (System.currentTimeMillis() - st));
38+
}).join();
4439
}
4540

4641
}

0 commit comments

Comments
 (0)