Play-Java + Futures/Promises.. where are we heading? [2.4+]

169 views
Skip to first unread message

Dominik Dorn

unread,
Aug 30, 2015, 5:29:53 PM8/30/15
to play-framework
I recently had a discussion on how to do asynchronous programming in a Play-Java project (2.4) 
in regards of where Play is heading (2.4 -> 2.5 -> 3.0).

Java 8 introduced CompletableFuture, yet Plays code base still is using play.libs.Promise. 
The question now is how to proceed, especially for writing own code. 

My current app will use a lot of WS-Requests against a backend system, so plays Promises are a natural fit for the webapp,
when the code stays in the project. 
However, we're also evaluating if we should create a API out of the created code, to allow reusing it in other Java projects.

One approach would be to use CompeletableFuture in the interfaces and map from Plays WSClients Promise -> CompletableFuture in the
Impl of the interface. However, when using this interface from a Play-Controller, we have to remap from a CompletableFuture to a Promise.

Another approach would be to adjust the Play-Framework to also allow Actions that return a CompletableFuture<Result> to be used in Controllers.

Any ideas/insights are greatly appreciated.

Cheers,
Dominik

Christian Schmitt

unread,
Aug 31, 2015, 4:17:01 PM8/31/15
to play-framework
Currently Play 2.5 will definitly support CompletionStage which is the interface of CompletionFuture, there is also an Issue and a Merged PR about that:
It looks like 2.4 and 2.5 will compile if you used F.Promise and from there on you should remove as many F.Promise as possible.

Niels Boldt

unread,
Sep 2, 2015, 2:07:59 PM9/2/15
to play-fr...@googlegroups.com
Currently Play 2.5 will definitly support CompletionStage which is the interface of CompletionFuture, there is also an Issue and a Merged PR about that:
It looks like 2.4 and 2.5 will compile if you used F.Promise and from there on you should remove as many F.Promise as possible.


"Replace play.libs.F.Promise with java.util.concurrent.CompletionStage in Java APIs"

Does it mean that only the java version will be affected. What does it mean with respect to Futures. Would it be possible in the scala version of 2.5 just to use java 8 futures as scala futures without a wrapper or would you still need to wrap them with something like https://github.com/scala/scala-java8-compat

Thanks
Niels 




Am Sonntag, 30. August 2015 23:29:53 UTC+2 schrieb Dominik Dorn:
I recently had a discussion on how to do asynchronous programming in a Play-Java project (2.4) 
in regards of where Play is heading (2.4 -> 2.5 -> 3.0).

Java 8 introduced CompletableFuture, yet Plays code base still is using play.libs.Promise. 
The question now is how to proceed, especially for writing own code. 

My current app will use a lot of WS-Requests against a backend system, so plays Promises are a natural fit for the webapp,
when the code stays in the project. 
However, we're also evaluating if we should create a API out of the created code, to allow reusing it in other Java projects.

One approach would be to use CompeletableFuture in the interfaces and map from Plays WSClients Promise -> CompletableFuture in the
Impl of the interface. However, when using this interface from a Play-Controller, we have to remap from a CompletableFuture to a Promise.

Another approach would be to adjust the Play-Framework to also allow Actions that return a CompletableFuture<Result> to be used in Controllers.

Any ideas/insights are greatly appreciated.

Cheers,
Dominik

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/eaff7f68-5da8-42d3-a22f-27f1522dd0f5%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4529722259
web: http://www.binaryconstructors.dk
mail: n...@binaryconstructors.dk
skype: nielsboldt
Reply all
Reply to author
Forward
0 new messages