Async / Await

10 views
Skip to first unread message

Thomas

unread,
Sep 27, 2018, 8:40:00 PM9/27/18
to CodenameOne Discussions
Just discovered this awsome library that I wanted to share with you: https://github.com/electronicarts/ea-async
When devlopping with react-native or Flutter I frequently use async/await when my app needs to communicate whith a distant server or a local database for example. Actually, promises and assync/await are such a powerfull concept that it is at the base of reactive programming, popularized by react.
So, I always regreted that java do not offer this type of concept as promises are so much convenient than having to deal with callbacks for complex asynchroneous workflows.
Actually, java made a first move in this direction with Java 8 that introduced CompletableFuture but it is so complex to use (seriously this API is a mess) that it was totally eclipsed by others Java 8 cool features (Lambdas, Streams, JSR 310, ...) and is barely used.
But this library, developped by Electronic Arts, abstract all the complexity of the CompletableFuture API and allows you to write async await code seamlessly. This way, you no longer have to handle two versions (a synchroneaous and an asynchroneous) of your network or native requests methods for example.
And where it is quite cool is that this lib is able to re-writte your async/await calls at runtime or build time, as you prefer. That means that it could very well be integrated into the CN1 build gradle process (so it would be directly packed with the CN1 IDE plugins) and we could use async/await in CN1 (it would requiere the CompletableFuture API to be ported to CN1 first though) !
Wouldn't it be cool?
That is clearly something I will try to do when I find some time ;)

Shai Almog

unread,
Sep 28, 2018, 12:47:14 AM9/28/18
to CodenameOne Discussions
You need a JVM agent to manipulate bytecode in runtime for this AFAIK. Probably not something we can integrate.

Thomas

unread,
Sep 28, 2018, 12:53:00 AM9/28/18
to CodenameOne Discussions
you don't need to manipulate bytecode in runtime. Like I said, this lib also offers you the possibility to manipulate the bytecode at compilation time (Option 4, the recommanded one, that makes this lib a transitive dependency). 
Reply all
Reply to author
Forward
0 new messages