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. | ||
| */ |
| } | ||
|
|
||
| @Override | ||
| public boolean hasMissingErrorConsumer() { |
|
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.
I think we should find a better name for this interface for several reasons:
HasDefaultErrorConsumersounds like marker interface that you need to use withinstanceofto get boolean result.- Interface
HasDefaultErrorConsumerand method namehasMissingErrorConsumer()are inconsistent. - Extensibility — do we plan to extend it with other functions to check
onNext/onCompleteimplementations?
There was a problem hiding this comment.
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.
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.
I let you people work out the naming.
There was a problem hiding this comment.
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.
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.
Composite is misleading and will show up in content assist when the developer types Composite
There was a problem hiding this comment.
to get to the disposable/exception variant mentioned.
There was a problem hiding this comment.
I'd call it LambdaConsumerIntrospection and hasCustomOnError()
There was a problem hiding this comment.
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.
nit: doesNotHaveMissingErrorConsumer?
|
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.
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.