-
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
2.x: @CheckReturnValue for public API #4878
Comments
I frequently fire up |
Yes either get the annotation from JSR 305 or I believe that creating our own annotation with the same name would also work. |
I think |
Alright will give it a try soon. |
Closing via #4881 |
What's the rationale behind forcing handling of a |
@markelliot It was decided anything that returns |
I'm on 2.0.5 and the source for subscribe looks like this: @CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable subscribe(Consumer<? super T> onNext) {
return subscribe(onNext, Functions.ERROR_CONSUMER, Functions.EMPTY_ACTION, Functions.emptyConsumer());
} |
Can't link to the source since GH is truncating at ~10k lines, but it looks like on master the code is the same. |
Why would you want to not handle the returned Disposable? |
Per above, I'm subscribing a consumer with intent to subscribe to every subsequent event. In that case, why should I handle the Disposable? |
Since you may need to |
Nope, intent is to subscribe for the remaining lifetime of my program. |
I see it differently but it might be just because I'm on Android and you're forced to dispose() when you hit a certain lifecycle method (e.g. Activity gets destroyed) |
@vanniktech we have quite a few subscriptions within our android app that are done from one Singleton to another and do not require disposing. One example is a memory cache observing a disk cache. |
Both having and not having this annotation makes sense. Can't you just ignore warnings at that location that can legally ignore the return value? |
You most certainly can the minor inconvenience we see is having to suppress the warning when using static analyzers/lint inspectors. For example Error Prone failed our build without |
I like to think of it as a forced documentation opportunity to indicate that you really don't care about the |
Cool, I guess I'm asking when one should check |
I'd add that the current code explicitly excepts methods with signature |
The no-arg |
I love the P.S. I finally found a perfect solution: https://github.com/uber/AutoDispose |
Ugh. After updating to RxJava 2.1.12, I have awful yellow warning highlighting everywhere. My two cents -- I hate
I find this much more readable than
I don't want to suppress that warning everywhere, so now I have to litter my code with local suppressions. |
I am with @autonomousapps on this one. I also have a convenience method to be used with
And I needed to add |
I see little point in using Plus Project-wide or even class-wide
Looks ugly. |
I'd like to kick the tires on this discussion again
I don't think I agree with that. For cases like @digitalbuddha mentioned with singletons or places where the scope of the execution is implicitly bound to the object (such as subscribing to an Android View's click events from within the View). To me, Thoughts? |
Views have a lifecycle you should be using to unsubscribe. For singletons, you can suppress with a comment to document the rare nature of that object and its exception to the rule. |
If you need to dispose at some point before the View is up for GC, sure. That's not the case 100% of the time though. I could be listening for detach events too, for instance, or tracking through multiple attach/detaches. There's no other lifecycle event to hook into beyond detach, but I'm happy to let the subscription die with the View once they're all leafs for GC if the subscription is only internal to the View. Another example would be synchronous cases like I just don't think this case is as rare as is being described. On top of that, conditions for cases like lifecycle management vary depending on the codebase, and often doesn't involve directly dealing with the |
Proposal PR for my followup comment in ReactiveX#4878 at . Will close if the discussion raised there still settles on keeping them.
How do you guys feel if the
@CheckReturnValue
annotation was added to certain public API methods?The one that would probably benefit the most in my opinion would be the
subscribe
method where you get aSubscription
orDisposable
back. In 99% of the cases you want to handle it.Also static analyze tools such as Error Prone could emit an error / warning.
The text was updated successfully, but these errors were encountered: