-
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
Inconsistent behavior between Observable, Single, and Completable subscriptions when propagating from a source Observable. #3706
Comments
Otherwise, this example of yours should pass: PublishSubject<String> stringSubject = PublishSubject.create();
Completable completable = stringSubject.toCompletable();
Subscription completableSubscription = completable.subscribe();
stringSubject.onCompleted();
assertTrue(completableSubscription.isUnsubscribed()); // This fails I forgot about this method, I'll post a PR to make it pass. |
Ah good to hear! Thanks for the quick response and glad it's a bug and not a feature in that regard :) |
Should this be labeled as a bug now for the |
Closing via #3707 |
👍 |
I've come across a couple of differences in the subscription behavior of
Observable
,Single
, andCompletable
that I was hoping I could get clarification on or bring up for discussion. The examples specifically revolve around converting an observable to those types and how its events are propagated.In a normal
Observable
, anonCompleted()
event automatically unsubscribes.This still holds true in
Single
, but with the added caveat that anonCompleted
event actually propagates toonError()
if no event has been emitted prior foronSuccess()
. This would be sort of ok considering theSingle
contract, but things get a little muddled in the sense thatonSuccess()
does not actually unsubscribe despite being considered a terminal event (or so I thought). What this means is thatonCompleted()
has to be called manually afteronSuccess()
Things get more confusing in
Completable
, which offers no auto-unsubscribe afteronComplete()
is called as far as I can tell.This would imply that you always need to save the subscription and manually unsubscribe in
onComplete()
ordoOnComplete()
.I'm not sure if this behavior still holds true when dealing with "pure"
Single
andCompletable
subscriptions, I can investigate more if need be.It does seem inconsistent to me, or at the very least prone to causing passive leaks or unexpected behavior due to subscriptions living on past "terminal" events. Maybe some clarification is needed on what constitutes a "terminal" event in
Single
andCompletable
. Would love to get some more insight from the collaborators that have worked on these.The text was updated successfully, but these errors were encountered: