Dear all,
I was trying to search through the archive and couldn't find any mention of this (looked for async, await, publisher, reactive streams), but please direct me if this has already been discussed.
Would be very nice to be able to write reactive code using plan Java in a way similar to how Kotlin co-routines or JavaScript async/await work. Basic idea is to let the compiler rewrite the code to make it suspendable.
Initial idea is that any method could be annotated with @Async, and then a special keyword 'await' (as a static function) could be used to express asynchronous reactive logic in a linear way. For example:
@Async public String sayHello(Flow.Publisher<String> name) {
return "Hello, " + await(name) + "!";
}Flow.Publisher<T> is from reactive streams specification, and it's the interface extended by many reactive frameworks, most notably Project Reactor and RxJava.
I've got few more ideas on what this could de-lombok into, and how to support different reactive libraries, but wanted to stop here and see what the community thinks?
Igor