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

Maybe concat with firstElement still call second Maybe although the first emit value #5100

Closed
ekosuhariyadi opened this issue Feb 16, 2017 · 2 comments

Comments

@ekosuhariyadi
Copy link

Hi, I'm relatively new to RxJava.

I tried RxJava 2.0.6 (previously 2.0.5) to check if it still produces the same result.

Here my code (still using Java 6)

Maybe<String> m1 = Maybe.create(new MaybeOnSubscribe<String>() {

    @Override public void subscribe(MaybeEmitter<String> e) throws Exception {
        System.out.println("m1 called");
        e.onSuccess("m1");
    }
});
Maybe<String> m2 = Maybe.create(new MaybeOnSubscribe<String>() {

    @Override public void subscribe(MaybeEmitter<String> e) throws Exception {
        System.out.println("m2 called");
        e.onSuccess("m2");
    }
});
Disposable subscribe = Maybe.concat(m1, m2)
        .firstElement()
        .subscribe(new Consumer<String>() {

            @Override public void accept(String t) throws Exception {
                System.out.println(t);
            }
        });

the output :
m1 called
m1
m2 called

Is it correct or not? Because while using Observable, the second Observable is not called when the first one already emit value

Thanks

@akarnokd
Copy link
Member

Hi and thanks for reporting. This is a bug in the underlying concat operator that doesn't expect a cancellation (happening due to firstElement) after emitting an item and happily subscribes to the next source, triggering subscription side-effects but actually cancelling out that new source immediately.

I'll post a fix shortly.

@akarnokd
Copy link
Member

Closing via #5101.

Temporary workaround: add Maybe.empty() between the sources to absorb the extra subscription.

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