Skip to content

Make ListenableFuture lambda compliant [SPR-11820] #16440

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

Closed
spring-projects-issues opened this issue May 26, 2014 · 5 comments
Closed

Make ListenableFuture lambda compliant [SPR-11820] #16440

spring-projects-issues opened this issue May 26, 2014 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 26, 2014

Sébastien Deleuze opened SPR-11820 and commented

When building a Spring 4 / Java 8 application, we can't use lambda with ListenableFuture since ListenableFutureCallback is not a functional interface (2 methods to implement).

5 proposals to improve this:

  1. Modify ListenableFutureCallback: it will break API so it is not an option (even if it would be the cleaner solution)
  2. Add another method to ListenableFuture with a callback parameter with just one method like mongoDB MongoFuture and SingleResultCallback.
  3. Add new fluent methods to ListenableFuture with single method callbacks allowing to write code like listenableFuture.onSuccess(...).onFailure(...)
  4. Add default implementation to ListenableFutureCallback#onFailure() interface : not possible since it would require Java 8 for main code
  5. Change nothing and wait for a future version of Spring that will require Java 8 and use native CompletableFuture

My prefered solution is the 3rd.

Any feedback or advice ?


Affects: 4.0.5

Issue Links:

Referenced from: commits 4e25a14, 86e8bda

1 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

As discussed yesterday, I'm in favor of option 3 as well. Let's try to roll this into 4.1 still.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Here is my first try, feedbacks welcomed !

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

The name ListenableFutureBuilder doesn't seem right. More importantly though the current proposal allows adding one success and one failure callback only. Then the builder returns ListenableFutureCallback which is odd since a callback should be input, not a return value. I'd expect to be able to chain onSuccess and onFailure callbacks in any order.

Shouldn't it look something like this:

public interface ListenableFuture<T> extends Future<T> {

	void addCallback(ListenableFutureCallback<? super T> callback);

	ListenableFuture<T> onSuccess(ListenableFutureSuccessCallback<T> callback);

	ListenableFuture<T> onFailure(ListenableFutureFailureCallback callback);

}

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Thanks for your feedback Rossen Stoyanchev. Here is a second try that match with your API proposal.

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Pull request #571 submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants