Skip to content

Commit 2e53fa9

Browse files
committed
Update HttpAsyncResponse.java
1 parent 7093015 commit 2e53fa9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

http-client/src/main/java/io/avaje/http/client/HttpAsyncResponse.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@
1010
/**
1111
* Async processing of the request with responses as CompletableFuture.
1212
*
13+
* <h4>Testing and .join()</h4>
14+
* <p>
15+
* Note that when testing with async requests we frequently use {@code .join()}
16+
* on the {@code CompletableFuture} such that the main thread waits for the async
17+
* processing to complete. After that various asserts can run knowing that the
18+
* async callback code has been executed.
19+
*
20+
* <h4>Example using .join() for testing purposes</h4>
21+
* <pre>{@code
22+
*
23+
* client.request()
24+
* ...
25+
* .POST().async()
26+
* .bean(HelloDto.class)
27+
* .whenComplete((helloDto, throwable) -> {
28+
* ...
29+
* }).join(); // wait for async processing to complete
30+
*
31+
* // can assert now ...
32+
* assertThat(...)
33+
*
34+
* }</pre>
35+
*
1336
* <h4>Example async().bean()</h4>
1437
* <p>
1538
* In this example POST async that will return a bean converted from json response.

0 commit comments

Comments
 (0)