Hello Team,
I there way to execute some code asynchronously in handler and fill response in callback?
I started with straightforward code like:
HttpHandler asyncHandler = (HttpServerExchange exchange) -> {
client.execute(new HttpGet("https://newton.now.sh/"), new FutureCallback<HttpResponse>() {
@Override
public void completed(HttpResponse result) {
System.out.println("Received.");
exchange.getResponseSender().send("Received.");
}
@Override
public void failed(Exception ex) {
System.out.println("Failed.");
exchange.getResponseSender().send("Failed.");
}
@Override
public void cancelled() {
System.out.println("Cancelled.");
exchange.getResponseSender().send("Cancelled.");
}
});
};
When I run this code completed method called, but nothing written in response (since exchange already end)
With no luck too.
So my question is how to do async tasks in handlers.