You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems misleading that replay(1).refCount() != cache(1), especially when replay().refCount() == cache().
It's especially odd because each one cannot mimic the behavior of the other - cache() has no variant that limits the number of items to replay, whereas replay() has no variant that allows you to hint how large the ReplaySubject should be.
I see that this has been covered before (#1591, #2913), but I still feel like something could be done to clear up the matter. Not exactly sure what - maybe all it'd take is not having the javadoc for cache() reference replay().
The text was updated successfully, but these errors were encountered:
I agree that caching a limited number of elements using cache() would be handy sometimes, but it is important to note that replay().refCount() does not behave equal to cache() in all situations.
For example:
int i = 0; // actually a field or static
Observable<Integer> cached = Observable
.defer(() -> Observable.just(i++, i++))
.cache();
cached.subscribe(i -> System.out.println("sub 1: " + i));
cached.subscribe(i -> System.out.println("sub 2: " + i));
prints
sub 1: 0
sub 1: 1
sub 2: 0
sub 2: 1
compared to
int i = 0; // actually a field or static
Observable<Integer> replayed = Observable
.defer(() -> Observable.just(i++, i++))
.replay().refCount();
replayed.subscribe(i -> System.out.println("sub 1: " + i));
replayed.subscribe(i -> System.out.println("sub 2: " + i));
It seems misleading that
replay(1).refCount()
!=cache(1)
, especially whenreplay().refCount()
==cache()
.It's especially odd because each one cannot mimic the behavior of the other -
cache()
has no variant that limits the number of items to replay, whereasreplay()
has no variant that allows you to hint how large theReplaySubject
should be.I see that this has been covered before (#1591, #2913), but I still feel like something could be done to clear up the matter. Not exactly sure what - maybe all it'd take is not having the javadoc for
cache()
referencereplay()
.The text was updated successfully, but these errors were encountered: