-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Add ActionListener#run #93338
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 ActionListener#run #93338
Conversation
It's pretty common to run a block of code in a `try ... catch` block that just passes exceptions off to a listener's `onFailure` method. This commit adds a small utility to encapsulate this, enabling some one-liners.
|
Pinging @elastic/es-distributed (Team:Distributed) |
| } catch (Exception e) { | ||
| listener.onFailure(e); | ||
| } | ||
| } |
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.
I wonder if that makes sense to have it non static?
public void completeWith(CheckedConsumer<ActionListener<T>, Exception> action) {
try {
action.accept(this);
} catch (Exception e) {
this.onFailure(e);
}
}
and usage:
listener.completeWith(it -> {
...
})
Though I am not sure if this is a better naming or actually simplifies the usage
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.
Yeah we could open that debate about most of these utilities. I'll stick with the common pattern for now tho.
|
Welp I think I broke the world here. I'm sure it's something obvious but I don't see what. I'll get back to this at some point. |
tlrx
left a comment
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.
I left a comment that could explain the test failures
| FileInfo fileInfo = fileInfos.get(); | ||
| if (fileInfo != null) { | ||
| fileSnapshotter.accept(context, fileInfo); | ||
| } |
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.
The listener must be completed here:
| } | |
| } | |
| l.onResponse(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.
Aha of course. ActionRunnable#run, the gift that keeps on giving.
It's pretty common to run a block of code in a `try ... catch` block that just passes exceptions off to a listener's `onFailure` method. This commit adds a small utility to encapsulate this, enabling some one-liners.
It's pretty common to run a block of code in a
try ... catchblock that just passes exceptions off to a listener'sonFailuremethod. This commit adds a small utility to encapsulate this, enabling some one-liners.