Skip to content

shareReplay({ refCount: true }) has different behavior with share() #6731

Answered by voliva
loadingwyn asked this question in Q&A
Discussion options

You must be logged in to vote

I think it's as per design. Note that the medium article says how there's no need for shareReplay anymore: i.e. all/most of the overloads with shareReplay you should be able to do with share. But doesn't say that shareReplay({ refCount: true }) would have to behave the same way as share.

The docs for shareReplay say:

This operator is a specialization of replay that connects to a source observable and multicasts through a ReplaySubject constructed with the specified arguments. A successfully completed source will stay cached in the shareReplayed observable forever, but an errored source can be retried.

And this explains why if you add in a take(3) to the first subscription it works as y…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by kwonoj
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #6729 on December 27, 2021 02:54.