Skip to content
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

Document Observables/Flowables.cache() #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thomasnield
Copy link
Contributor

Following up on #8

@thomasnield
Copy link
Contributor Author

I'm a little confused why providing timed arguments doesn't result in automatic resetting at those time intervals. Maybe there is something wrong with my implementation.

import com.github.davidmoten.rx2.Observables;
import com.github.davidmoten.rx2.observable.CloseableObservableWithReset;
import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;

import java.time.LocalTime;
import java.util.concurrent.TimeUnit;

public class CachedObservableDemo {

    public static void main(String[] args) {

        // declare source
        Observable<LocalTime> source =
                Observable.fromCallable(LocalTime::now);

        // create CloseableObservableWithReset
        CloseableObservableWithReset<LocalTime> closeableSource =
                Observables.cache(source, 5, TimeUnit.SECONDS, Schedulers.computation());

        //create timed cache
        Observable<LocalTime> timedCache = closeableSource.observable();


        // initial subscription
        timedCache.subscribe(System.out::println);

        // sleep 3 seconds, still prints same value
        sleep(3000);
        timedCache.subscribe(System.out::println);

        //  a new cache is built on next subscription
        sleep(3000);
        timedCache.subscribe(System.out::println);
    }

    public static void sleep(long millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

@codecov-io
Copy link

codecov-io commented Jun 29, 2017

Codecov Report

Merging #9 into master will decrease coverage by 0.38%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master       #9      +/-   ##
============================================
- Coverage     88.92%   88.54%   -0.39%     
+ Complexity      461      455       -6     
============================================
  Files            63       62       -1     
  Lines          3260     3124     -136     
  Branches        408      391      -17     
============================================
- Hits           2899     2766     -133     
  Misses          235      235              
+ Partials        126      123       -3
Impacted Files Coverage Δ Complexity Δ
.../java/com/github/davidmoten/rx2/StateMachine2.java 86.2% <0%> (-3.45%) 1% <0%> (ø)
...c/main/java/com/github/davidmoten/rx2/Actions.java 90.9% <0%> (-1.95%) 4% <0%> (-1%)
...main/java/com/github/davidmoten/rx2/Functions.java 90% <0%> (-1.67%) 4% <0%> (-1%)
...main/java/com/github/davidmoten/rx2/RetryWhen.java 76.59% <0%> (-1.19%) 9% <0%> (ø)
...in/java/com/github/davidmoten/rx2/Observables.java 46.66% <0%> (-1.16%) 4% <0%> (ø)
...internal/flowable/FlowableFetchPagesByRequest.java 92.85% <0%> (-1.09%) 2% <0%> (ø)
...rx2/internal/flowable/TransformerStateMachine.java 79.31% <0%> (-1.02%) 6% <0%> (ø)
...main/java/com/github/davidmoten/rx2/Flowables.java 53.84% <0%> (-0.88%) 11% <0%> (ø)
...idmoten/rx2/internal/flowable/FlowableReverse.java 91.66% <0%> (-0.65%) 4% <0%> (ø)
...m/github/davidmoten/rx2/flowable/Transformers.java 89.41% <0%> (-0.48%) 32% <0%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 19b2c28...30aeded. Read the comment docs.

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

Successfully merging this pull request may close these issues.

2 participants