Async/await for reactive streams

65 views
Skip to first unread message

Igor Lobanov

unread,
May 6, 2023, 6:44:31 AM5/6/23
to Project Lombok
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

Mat Jaggard

unread,
May 6, 2023, 5:21:27 PM5/6/23
to project-lombok
I think it's a great idea but likely a difficult concept to implement (I think a new keyword is not possible for example) however the bigger picture is improving here and it might not be needed in a few months when Project Loom arrives fully which will allow the same concepts (albeit very differently implemented) to be built into the JDK.

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/project-lombok/209a84a1-133f-4ebc-ad68-6bce24912299n%40googlegroups.com.

Michael Berry

unread,
May 6, 2023, 5:36:43 PM5/6/23
to project...@googlegroups.com
If the Java ecosystem was heading down the route of fuller adoption of reactive libraries and frameworks, then something like this could well be worth exploring (though personally I don't think it really fits into lombok's scope, but that's a side point.)

However, as said above, if anything the community is moving well away from such frameworks with the introduction of Loom. Loom should give most, if not all of the reactive advantages whilst allowing developers to code in a conventional way, using conventional tools - which would negate the need for anything like an async annotation. I'm sure there will be certain side cases where the DSL offered by reactive frameworks still means they're a viable choice - but at this point it would likely be such a niche that inclusion in Lombok wouldn't be warranted.



--
Thanks,

Michael
Reply all
Reply to author
Forward
0 new messages