Skip to content

OperatorDoOnEach breakes latter subscribtions after error wrapping lift #1689

Closed
@MikolajKakol

Description

@MikolajKakol

I have failing test:
final AtomicInteger count = new AtomicInteger(3);

    Observable.range(0, count.get())
            .map(THROW_ON_ODD)
            .map(i -> i) // #1
            .flatMap(Observable::just) // #2
            //.doOnNext(System.out::println) // #3
            .doOnEach(System.out::println) // #4
            .lift(OPTION_WRAP())
            .subscribe(
                    op -> {
                        System.out.println(op.toString());
                        count.decrementAndGet();
                    },
                    e -> System.out.println("It never will be printed" + e.getClass().getSimpleName()),
                    () -> System.out.println("end")
            );

    assertEquals(0, count.get());

All the magic is in lift in which I wanted to have error wrapping using something similar to com.google.common.base.Optional. So when onError is emitted I wrap it to error result and when onNext is emmited I wrap it valid result. Whole test source is here: https://gist.github.com/novemberox/e2b1b4e289ac45162847

Problem is with line marked as #3 and #4, if any of those is not commented test fails. Order of lines #1-4 doesn't matter, result is always the same. Since doOnXXX is side effect that shouldn't affect core observable I think is a bug.


You might ask me while I'm trying to treat error as valid data. Common thing is to have some action triggered from UI that would trigger some IO action and display result back to the UI.

I wanted have my UI to be expresed more as FRP so when UI is created I want to have few Subjects that would emit data events like text change or button clicked this way I can do all my business logic it that very moment.

However that is not working at all with Rx paradigm that after onError nothing should be emitted. This paradigm doesn't work well with UI, because I want to be able do IO at every button click event if it fails, my UI can handle both error and result nicely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions