question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal for ConnectableObservable#connectOnSubscribe

See original GitHub issue

ConnectableObservable currently supports two standard ways to manage subscriptions to the source:

  1. connect which immediately subscribes to the source and never unsubscribes (unless the source completes)
  2. 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:closed
  • Created 6 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
cartantcommented, Jan 19, 2018

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/3127

1reaction
cartantcommented, Jan 19, 2018

You might find this comment of Paul Taylor’s interesting. In fact, that entire thread is interesting.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found