-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Implement LambdaConsumerIntrospection #5590
Conversation
Followup from ReactiveX#5569, and allows you to introspect if the resulting observer has missing error consumption and subsequently supplies a default (throwing) one.
Wasn't sure how you'd want to do the naming. Can work on adding some tests if this looks good, wanted to get something up for API review early |
|
||
/** | ||
* An interface that indicates that the implementing type has default implementations for error consumption. | ||
*/ |
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.
@since 2.1.4 - experimental
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.
@@ -101,4 +104,9 @@ public void dispose() { | |||
public boolean isDisposed() { | |||
return get() == DisposableHelper.DISPOSED; | |||
} | |||
|
|||
@Override | |||
public boolean hasMissingErrorConsumer() { |
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.
A test would be great.
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 naming is fine with me. |
Codecov Report
@@ Coverage Diff @@
## 2.x #5590 +/- ##
============================================
+ Coverage 96.15% 96.23% +0.08%
- Complexity 5827 5836 +9
============================================
Files 632 632
Lines 41459 41465 +6
Branches 5742 5742
============================================
+ Hits 39863 39904 +41
+ Misses 638 621 -17
+ Partials 958 940 -18
Continue to review full report at Codecov.
|
Should I add this to other types' observers too? Or do you want to start with this first? |
That would be great! |
Btw @hzsweers, you can solve this right now by overriding (via reflection) Although current WIP looks fine for the most part 👍 |
yeah I'd prefer something in the public API :). @akarnokd should there be a separate |
Just reused for now, let me know if you want me to make it separate. I think I've covered the other observer possibilities, let me know if there's any others I should cover |
* @since 2.1.4 - experimental | ||
*/ | ||
@Experimental | ||
public interface HasDefaultErrorConsumer { |
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 think we should find a better name for this interface for several reasons:
HasDefaultErrorConsumer
sounds like marker interface that you need to use withinstanceof
to get boolean result.- Interface
HasDefaultErrorConsumer
and method namehasMissingErrorConsumer()
are inconsistent. - Extensibility — do we plan to extend it with other functions to check
onNext
/onComplete
implementations?
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'd definitely get rid of "default" and "missing" from both. The negated method is really confusing. There's already Has*
types which do similar things so I don't agree that it needs changed.
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.
Hm, last sentence dropped from my comment for some reason.
Depending on answer to №3 I have following interface names on my mind ObserverIntrospection
/SubscriberIntrospection
or ErrorConsumerIntrospection
, hope someone has better suggestions :)
The negated method is really confusing.
Huh, indeed! Didn't notice that until you pointed
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 let you people work out the naming.
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.
for the method, how about just a simple isNotImplemented()
or isThrowing()
?
Assuming the interface itself gets named HasErrorConsumer
?
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.
People will most likely mistreat CompositeObserver
and think of it as of a combination of observers because that's how CompositeDisposable
and CompositeException
work.
ObserverInstrumentation
/ObserverIntrospection
? Such a name also more clearly delivers the intention of consume-only public API
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.
Composite
is misleading and will show up in content assist when the developer types Composite
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.
to get to the disposable/exception variant mentioned.
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'd call it LambdaConsumerIntrospection
and hasCustomOnError()
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.
Good points. The Introspection
moniker feels off to me, mostly because I consider introspection an act and don't necessarily think of it as a noun/type at first. I don't know what a better word would be though. Updated in bae194c
} | ||
|
||
@Test | ||
public void isNotMissingErrorConsumer() { |
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.
nit: doesNotHaveMissingErrorConsumer
?
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.
Made them clearer in 500df33
I agree the names could be better, will update tomorrow |
Ok I've updated the tests and the naming based on CR. The only remaining bit I think is whether or not to use a global introspection interface or make one per observer for better parity. Thoughts? |
Depends on which level of I'd create an interface per Rx-type, so you could hook into these ie: Because if we'll decide to add introspection API for other callbacks like
|
Yeah I meant per-type. I think the name is fine as a specific thing since it's only applicable to composed observers like lambdaobserver. |
I think there is no need to have 5 versions of the same interface; there is always the Subscriber/Observer type discoverable: public static void errorNotImplemented(Object target) {
if (target instanceof LambdaConsumerIntrospection) {
if (target instanceof SingleObserver) {
// ...
}
if (target instanceof Subscriber) {
// ...
}
}
} |
that works for me. I think this PR is complete then |
* implementation is missing an error consumer and thus using a throwing default implementation. | ||
*/ | ||
@Experimental | ||
boolean hasCustomOnError(); |
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.
Shouldn't we provide hasDefaultOnError()
instead? cc @JakeWharton
Because if you think about it from RxJava perspective — that's what library can say about itself: is something has a default value/implementation in compare to what library thinks is default.
hasCustomOnError()
basically checks for hasDefaultOnError()
and then negates the result which is kinda confusing.
TL;TR: "custom" in the API feels wrong, but maybe it's just me :)
@akarnokd questionable decision about types, up2u of course |
If you want to hijack those consumer types, you already know the target type and which signal types it can deliver. Therefore, if they implement the same broad interface, the impossible methods can return false or throw an |
Followup from #5569, and allows you to introspect if the resulting observer has missing error consumption and subsequently supplies a default (throwing) one.