We currently use Netty's EventLoop API and JDK's ScheduledExecutorService in our API as they are. They return its own future implementation or java.util.concurrent.Future which doesn't support true asynchronous programming. It'd be really nice if we define a new API that returns a CompletableFuture, which will allow writing much less verbose code like the following:
@Get
CompletableFuture<HttpResponse> delayedResponse(ServiceRequestContext ctx) {
return ctx.eventLoop.schedule(() -> {
.. do something ..
return HttpResponse.of(...);
}, 5, TimeUnit.SECONDS);
}
vs.
@Get
CompletableFuture<HttpResponse> delayedResponse(ServiceRequestContext ctx) {
ScheduledFuture<HttpResponse> sf = ctx.eventLoop.schedule(() -> {
.. do something ..
HttpResponse.of(...);
}, 5, TimeUnit.SECONDS);
CompletableFuture<HttpResponse> f = new CompletableFuture<>();
sf.addListener(
...
.. propagate the result to `f` ..
);
return f;
}
We currently use Netty's
EventLoopAPI and JDK'sScheduledExecutorServicein our API as they are. They return its own future implementation orjava.util.concurrent.Futurewhich doesn't support true asynchronous programming. It'd be really nice if we define a new API that returns aCompletableFuture, which will allow writing much less verbose code like the following:vs.