Proposal for ConnectableObservable#connectOnSubscribe
See original GitHub issueConnectableObservable
currently supports two standard ways to manage subscriptions to the source:
connect
which immediately subscribes to the source and never unsubscribes (unless the source completes)refCount
which subscribes when the number of subscriptions goes up from 0, and unsubscribes the source when the number of subscriptions hits 0 again.
Something I ran into a couple times now is a mixture of the two: subscribe to the source on the first subscription, but then stay connected even if all subscriptions go away. Perhaps I’m also just missing something and this can be trivially done already in a natural way (?), but if not, I’d love to see it. 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
java - ConnectableObservable, disconnecting and reconnecting
That will stop events from being propagated to observers but it will not unsubscribe them from the ConnectableObservable. If you call connect ......
Read more >ConnectableObservable (RxJava Javadoc 1.3.8) - ReactiveX
Returns an Observable that automatically connects to this ConnectableObservable when the specified number of Subscribers subscribe to it.
Read more >ConnectableObservables (part 2) - Advanced Reactive Java
RxJava has two operators that return a ConnectableObservable: publish() ... If one unsubscribes the Subscription returned by the connect() ...
Read more >Chapter 7. Controlling the observable temperature - Rx.NET in ...
To automatically unsubscribe the ConnectableObservable when there are no more observers, use the RefCount operator. The Replay operator renders a hot observable ...
Read more >Advanced Reactive Java - RSSing.com
Finally, let's see how one can implement the unsubscribe() method. ... a 'control' object that lets it cancel the connection and request more...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yep, but the idea expressed in the comment’s snippet is useful. I used it to create an operator that waits a specified amount of time before unsubscribing: https://github.com/cartant/rxjs-etc/blob/master/source/let/refCountAuditTime.ts
You could also look at the implementation of
shareReplay
- in this repo - as it does what you seem to want: it never unsubscribes. Some parts of that implementation can be removed, too. See this thread: https://github.com/ReactiveX/rxjs/issues/3127You might find this comment of Paul Taylor’s interesting. In fact, that entire thread is interesting.