-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add lambda friendly addCallback. #16
Conversation
Looks good. My only concern is that we allow null for the consumers (for one or for both). |
You can attach callbacks that are run depending on the results of a future: | ||
```java | ||
final ListenableFuture<A> future = getFuture(); | ||
FuturesExtra.addCallback(future, a -> System.out.println(a), e -> e.printStackTrace()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this example could also use method references: System.out::println and Throwable::printStackTrace
* only be run if the future fails. | ||
* @param future a ListenableFuture to attach the callbacks to. | ||
* @param success a consumer, to be called with the result of the successful future. | ||
* @param failure a consumer, to be called with the result of the failed future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document the nullability-rules of the parameters (both may not be null)
* @param future a ListenableFuture to attach the callbacks to. | ||
* @param success a consumer, to be called with the result of the successful future. | ||
* @param failure a consumer, to be called with the result of the failed future. | ||
* @throws NullPointerException if the {@param success} and {@param failure} are null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is slightly unclear (not obvious that both have to be null for it to throw) but i dont want to reject the change based on that.
Add lambda friendly addCallback.
No description provided.