Skip to content

Conversation

ekchang
Copy link

@ekchang ekchang commented Oct 24, 2016

#4702

Uses the same test as the Observable one.

@codecov-io
Copy link

codecov-io commented Oct 24, 2016

Current coverage is 84.07% (diff: 100%)

Merging #4757 into 1.x will increase coverage by 0.23%

@@                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   

Powered by Codecov. Last update 5e3f6c4...69b5b16

* @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();
Copy link
Contributor

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.

Copy link
Author

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() {
Copy link
Contributor

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.

Copy link
Member

@akarnokd akarnokd left a 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
Copy link
Member

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();
Copy link
Member

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.

@akarnokd akarnokd added this to the 1.3 milestone Oct 24, 2016
@martinbonnin
Copy link

Sorry I'm late to the party here. This seems to be rxjava1.x only. Is this going to reach 2.x ?

@JakeWharton
Copy link
Contributor

It's in 2

@martinbonnin
Copy link

Uupps, right ! Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants