-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
PublishSubject is broken? #1180
Comments
ConnectableObservable co = s.replay(1);
co.doOnNext(v -> { System.out.println(v); }).subscribe();
co.connect();
s.onNext("hello"); |
Thank you, that explains the operation. And also shows that the connect is a must, so it is not possible to chain the calls as I did. Then what is the point of having replay() return anything that resembles an Observable? Or is there some autoconnect method too? |
There isn't any simple operator for that, though there is an enhancement request (somewhere among the issues) to add those variants. The closest auto-connect version is this: s.replay(o -> o, 1).doOnNext(...).subscribe(); |
Ugh, this doesn't look good. Especially in Java if that nop function has no static method creator. Thanks again. |
Note that if you think you need subjects, there is a 99% chance you can find a more elegant solution that does not require subjects. Really. |
There is |
Thank you for the support. I'll look at At the same time, I see that the API of Probably an explicit note in the documentation about @headinthebox I know, I usually try to avoid subjects. However, I have a two way causal chain in my case. In one way goes the calculation result, in the other way goes the cancellation. It's possible to implement without subjects but it will not differ much from what subjects already provide and it would break the scope of my signals. Currently every signal is used only inside a single object and it is pretty easy to follow it this way. Also, it makes debugging a lot easier. But thanks for the note. |
The wiki documentation is more explicit about the need to call connect(): https://github.com/Netflix/RxJava/wiki/Connectable-Observable-Operators On Fri, May 9, 2014 at 12:00 PM, andrask [email protected] wrote:
David M. Gross |
@DavidMGross Adding that single line to the |
Your wish is my command: On Fri, May 9, 2014 at 1:08 PM, andrask [email protected] wrote:
David M. Gross |
@DavidMGross You're awesome! Instead of whining, I should have done it. Fortunately, there is always next time in open source and I love it! |
Can I ask someone to explain me why this code terminates without writing out anything?
While debugging, I see that the subject has no subscribers. True, there are no direct subscribers but the
replay()
creates a multicast connection.The text was updated successfully, but these errors were encountered: