-
Notifications
You must be signed in to change notification settings - Fork 3k
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
refCount
with delay
#4033
Comments
Thank you for writing this up. I ran into the same thing. For now, I'm actually memoizing the slow operation (it was an http call) and allowing the stream to reset. It's not perfect, but it seems to work in my case. The operator (or flag to |
@aaronjensen IIRC, I ended up working with @cartant on a |
That's helpful, thank you @OliverJAsh. It looks like that package has |
This has come up a few times, and now that we've revamped the Off the top of my head, maybe something like (not at all set on this, it requires some thought): source$.pipe(
share({
resetOnRefCountZero: () => timer(1000) // Where it could be a boolean or a reset timer factory?
});
) I'll add this to agenda items. |
Feature Request
Is your feature request related to a problem? Please describe.
I have a
Observable<Array<Observable<T>>>
which I want to map toObservable<Array<T>>
.When a new array is emitted, the inner observables should unsubscribe/subscribe as follows:
Observable
exists in previous array and the new/current array, retain pre-existing subscriptionObservable
did not exist in previous array but does exist in new/current array, create new subscriptionObservable
existed in previous array but does not exist in new/current array, unsubscribe from pre-existing subscriptionI hoped to achieve this using
switchMap
on the outer observable and then passingArray<Observable<T>>
intocombineLatest
. However,switchMap
will unsubscribe from its previous innerObservable
before subscribing to the new innerObservable
, which means inner subscriptions are not retained as desired.Example:
Describe the solution you'd like
To offset the fact that
switchMap
unsubscribes to the previous inner observable before subscribing to the new inner observable, I would like therefCount
ing to be delayed, thereby ensuring that subscriptions to the inner observables are retained.This is the solution suggested in this article. An alternative
refCount
with delay operator can be found here.Describe alternatives you've considered
(If this is new operator request) describe reason it should be core operator
From my research this seems like something people want but it's not easy to do. I discovered issues/articles/examples on the internet, but there doesn't seem to be anything in the core to help with this.
Additional context
refCountWithDelay
implementation: https://gist.github.com/marinho/3637210b13c0f298e1692a0b7b104e64delayedRefCount
implementation: https://medium.com/@volkeron/rxjs-unsubscribe-delay-218a9ab2672eThe text was updated successfully, but these errors were encountered: