-
Notifications
You must be signed in to change notification settings - Fork 102
Can't use thenCompose with FutureConvertersImpl - doThenCompose calls toCompletableFuture #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey @rkuhn or @bantonsson, could I ask one of you to a look at this? |
I believe the exception should be removed, and should return 'this' in the toCompletableFuture method but I don't understand all of the impacts. The implementation needs to work with thenCompose to be useful though. I'm writing a book at the moment (Learning Akka, Packt) - I'm trying to introduce this library as the mechanism for handling future's from Java8, which it otherwise seems to be a good fit for. Also where I'm working we're starting to lift out code from a play application into libraries and I'd like to replace play Promises with completableFutures to break the Play2 dependency. If there is another approach I should look at, or if you need any help, please let me know. I can make a PR and test cases if desired. |
I am not sure if I am having the same problem. But maybe you can point me in the right direction. I have a Scala API which returns |
Right - it throws the UnsupportedOperationException because the Java8 CompletableFuture implementation calls toCompletableFuture in it:
thenCompose should handle the CompletionStage returned from toJava but it won't as long as the exception is thrown. The scala-java8-compat library's toJava returns a CompletableFuture implementation, but won't let you call the toCompletableFuture method with the intention of hiding the completion methods of the future (as the scala future will be completed). You can cast to CompletableFuture to use get etc as the CompletionStage passed is actually a CompletableFuture. I think the only option is to replace the toCompletableFuture method with one that returns this. Otherwise this library is not very useful. |
Any word on this? Can I make a PR to stop throwing the exception? |
Sorry for the delay, this flew under my radar. I have not fully penetrated the whole problem, but from what you write it seems that indeed returning |
Another possibility would be to override doThenCompose to not call toCompletableFuture: we don’t need to return this more specific type, in particular if our CompletionStage is not supposed to implement the CompletableFuture contract (which I think is the point). |
Oh ya - I don't know why I didn't think of that. The oracle code wasn't
|
Yeah, somehow I also needed two weeks to figure this out ;-) BTW: the reason behind the slightly unorthodox code layout is that Doug’s goal was to make individual methods overridable without affecting the others—for better or worse. |
Hey Roland,
I thought this was the same version I was using before but not sure - other laptop is long gone.
Maybe you have some ideas - I only looked briefly at this. Looks a bit scary though. |
Since `toCompletableFuture` stopped throwing an `UnsupportedOperationException` in the previous commit, this use case is now supported. Fixes scala#29
Confirmed w/ example in the soon-to-be-published "Learning Akka" - Seems to be resolved in 0.6.0-SNAPSHOT. Just in time for it to go to print too :) thanks. I give this library mention for use in Java8. Worked w/ Java8 for a while and this is a very useful library for working with futures across the languages. |
0.6.0-SNAPSHOT I built and published locally. Confirmed the issue is fixed in my use cases. |
Hey, sorry to harass you around the holidays - are you able to publish 0.6.0 in the next couple weeks? |
@jasongoodwin 0.7.0 is the latest release, see the badge at the top of the README for a link: |
Sorry! I was looking at the 2.10 releases published in maven central. |
Hey I found an issue with this.
The FutureConvertersImpl throws an exception when toCompletableFuture is called:
Which is fine. However, if you do something like this:
thenCompose calls doThenCompose:
And if there aren't any exceptions, then it calls toCompletableFuture which causes failure.
Removing the exception causes everything to complete just fine.
Is there another way this can be handled other than throwing an exception?
The text was updated successfully, but these errors were encountered: