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

1.x: UnicastSubject does not replay onNext calls made prior to subscription if onError is also called prior to subscription. #5165

Closed
dano opened this issue Mar 8, 2017 · 5 comments

Comments

@dano
Copy link

dano commented Mar 8, 2017

I'm using RxJava 1.2.5. Consider this code:

    UnicastSubject<String> s = UnicastSubject.create();
    s.onNext("1");
    s.onNext("2");
    s.onError(new Exception("uh oh"));
    s.subscribe(System.out::println, System.out::println);

This outputs:
java.lang.Exception: uh oh

However, the same code using RxJava 2.0.7 version of UnicastSubject outputs:
1
2
java.lang.Exception: uh oh

Which is the behavior I expected from 1.x.

@akarnokd
Copy link
Member

akarnokd commented Mar 8, 2017

Hi. In RxJava 1.x the UnicastSubject is fail-fast and in 2.x it is delay-error. Currently, there is no option for the other mode in either major version.

@dano
Copy link
Author

dano commented Mar 8, 2017

@akarnokd Ah, I see. Thanks for the clarification. Is that documented somewhere that I'm missing? The UnicastSubject docs for 1.x gave me the impression that all events will get replayed once it's subscribed to, regardless of whether or not there's an error event. I also didn't find it mentioned in the "What's Different in 2.0" wiki.

Also, I noticed you added the "PR welcome" label - Are you looking for PRs that add a way to optionally (and not by default) switch to the currently unsupported mode for each major version? Meaning, add a way to delay-error on 1.x and/or a way to fail-fast on 2.x.

@akarnokd
Copy link
Member

akarnokd commented Mar 9, 2017

I also didn't find it mentioned in the "What's Different in 2.0" wiki.

This change was likely simply overlooked.

added the "PR welcome" label

Yes. Keep the current defaults in each version and add two factory methods:

public static <T> UnicastSubject<T> create(boolean delayError) {
    // ...
}
public static <T> UnicastSubject<T> create(int bufferSize, 
        Runnable onTerminate, boolean delayError) {
    // ...
}

@dano
Copy link
Author

dano commented Mar 9, 2017

@akarnokd Got it, thanks.

@akarnokd
Copy link
Member

Closing via #5195, #5217 and #5226.

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