Skip to content
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

RxJava 2.0.4 Observable calls dispose before terminal event. #4956

Closed
StanislavChumarin opened this issue Jan 4, 2017 · 3 comments
Closed

Comments

@StanislavChumarin
Copy link

Recently discovered behaviour that brings incorrect order for Observable.doFinally

Here is code to check

    @Test
    public void operationFinallyOrder() throws Exception {
        Single.error(new RuntimeException())
                .doOnDispose(() -> System.out.println("Single.doOnDispose"))
                .doFinally(() -> System.out.println("Single.doFinally"))
                .subscribe(o -> System.out.println("Single.onSuccess"),
                        t -> System.out.println("Single.onError"));
        System.out.println();

        Completable.error(new RuntimeException())
                .doOnDispose(() -> System.out.println("Completable.doOnDispose"))
                .doFinally(() -> System.out.println("Completable.doFinally"))
                .subscribe(() -> System.out.println("Completable.onComplete"),
                        t -> System.out.println("Completable.onError"));
        System.out.println();

        Observable.error(new RuntimeException())
                .doOnDispose(() -> System.out.println("Observable.doOnDispose"))
                .doFinally(() -> System.out.println("Observable.doFinally"))
                .subscribe(o -> System.out.println("Observable.onNext"),
                        t -> System.out.println("Observable.onError"),
                        () -> System.out.println("Observable.onComplete"));
        System.out.println();

        Observable.just(new Object())
                .doOnDispose(() -> System.out.println("Observable.doOnDispose"))
                .doFinally(() -> System.out.println("Observable.doFinally"))
                .subscribe(o -> System.out.println("Observable.onNext"),
                        t -> System.out.println("Observable.onError"),
                        () -> System.out.println("Observable.onComplete"));
    }

Output:

Single.onError
Single.doFinally

Completable.onError
Completable.doFinally

Observable.doOnDispose
Observable.doFinally
Observable.onError

Observable.onNext
Observable.doOnDispose
Observable.doFinally
Observable.onComplete

As you can see, order and amount of messages for Single and Completable are correct, but LambdaObserver calls dispose before terminal event. That triggers doFinally too early.
According to new lifecycle (confirmed here #4811) no messages Observable.doOnDispose should be there.

@akarnokd akarnokd added this to the 2.0 backlog milestone Jan 4, 2017
@akarnokd
Copy link
Member

akarnokd commented Jan 4, 2017

Indeed, Observable behaves differently from Flowable:

Flowable.onError
Flowable.doFinally

Flowable.onNext
Flowable.onComplete
Flowable.doFinally

I'll post a fix shortly.

@akarnokd
Copy link
Member

akarnokd commented Jan 4, 2017

See #4957

@akarnokd
Copy link
Member

akarnokd commented Jan 4, 2017

Closing via #4957

@akarnokd akarnokd closed this as completed Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants