-
Notifications
You must be signed in to change notification settings - Fork 7.6k
1.x: Add cache() to Single #4757
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
Conversation
Current coverage is 84.07% (diff: 100%)@@ 1.x #4757 diff @@
==========================================
Files 286 286
Lines 17751 17752 +1
Methods 0 0
Messages 0 0
Branches 2701 2701
==========================================
+ Hits 14882 14925 +43
+ Misses 1996 1957 -39
+ Partials 873 870 -3
|
* @see <a href="http://reactivex.io/documentation/operators/replay.html">ReactiveX operators documentation: Replay</a> | ||
*/ | ||
public final Single<T> cache() { | ||
return toObservable().cacheWithInitialCapacity(1).toSingle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this is a start. Ideally we would have a dedicated operator implementation that was low-overhead since we know the only thing that needs cached is a single item or complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I figured I'd go for the low hanging fruit of just getting a working API out there rather than try and tackle some implementation of CachedSingle
all at once.
* benefit of subsequent subscribers | ||
* @see <a href="http://reactivex.io/documentation/operators/replay.html">ReactiveX operators documentation: Replay</a> | ||
*/ | ||
public final Single<T> cache() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New operators need @Experimental
annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javadoc needs rephrasing at least.
@@ -1270,6 +1271,62 @@ public R call(Object... args) { | |||
} | |||
|
|||
/** | |||
* Returns a Single that subscribes to this Single lazily, caches its next event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Returns a Single that subscribes to a this Single lazily, caches its success or error event"
*/ | ||
@Experimental | ||
public final Single<T> cache() { | ||
return toObservable().cacheWithInitialCapacity(1).toSingle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought @JakeWharton wanted a native Single.cache
and not this type of reuse.
Sorry I'm late to the party here. This seems to be rxjava1.x only. Is this going to reach 2.x ? |
It's in 2 |
Uupps, right ! Thanks ! |
#4702
Uses the same test as the Observable one.