shareReplay and take operators #7067
avri87
started this conversation in
Report issues other than bug
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey,
I used shareReplay with refCount = true and bufferSize = 1 as for caching things which is great, but then I saw following thing:
Consider you have this:
const sourceObs: Observable<...> = .defer(() => {
console.log("exe");
return of(1).pipe(delay(1))
})
const sharedObs1 = sourceObs.pipe(
shareReplay({ bufferSize: 1,refCount: true }),
take(1)
)
const sharedObs2 = sourceObs.pipe(
take(1),
shareReplay({ bufferSize: 1,refCount: true }),
)
When we do following:
sharedObs1 .subscribe(() => {
setTimoue(() => sharedObs1.subscribe())
})
Then, sourceObs would be subscribed again, in the timeout callback handler, using a new ReplaySubject for multicasting... is it ok? or a bug?
When we do following:
sharedObs2 .subscribe(() => {
setTimoue(() => sharedObs2.subscribe())
})
Then, sourceObs is not subscribed again, in the timeout callback
Beta Was this translation helpful? Give feedback.
All reactions