By executing the code below, I was expecting to have "passed"
printed right away on console and then, 3 seconds later, postman's server delayed response ({"delay":"3"}
), but instead I'm having to wait 3 seconds to see "passed"
printed, after the server response. What am I doing wrong?
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://postman-echo.com/delay/3"))
.header("cache-control", "no-cache")
.header("postman-token", "6bac0475-7cd1-f51a-945f-2eb772483c2c")
.build();
client.sendAsync(request, BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
System.out.println("passed");