Skip to content

Subscription not disposed after onComplete with RxJava 2.x #5283

@alexvictoor

Description

@alexvictoor

Hello
I am not sure this is an issue, I would rather say this is a question.
I have noticed a different behavior between RxJava 1.x and RxJava 2.x
When an observable is completed, with RxJava 1.x subscriptions get unsubscribed:

BehaviorSubject<Object> subject = BehaviorSubject.create();
Subscription subscription = subject.subscribe();
subject.onCompleted();
System.out.println(subscription.isUnsubscribed()); // display true

However with RxJava2, the subscription is not disposed when the observable is completed:

Disposable subscription = null;
@Test
public void test() {
    BehaviorSubject subject = BehaviorSubject.create();
    Observer<? super String> observer = new Observer<String>() {
        
        public void onSubscribe(Disposable d) {
            subscription = d;
        }

        ...
    };
    
    subject.subscribe(observer);
    subject.onComplete();
    System.out.println(subscription.isDisposed());  // display false
}

Is it a wanted behavior? If so is this behavior documented somewhere?
Thanks a lot for your help

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions