These are chat archives for ReactiveX/RxJava

19th
Jun 2017
Rafael Guillen
@rguillens
Jun 19 2017 13:41
@i-schuetz , I told you to use publish().refcount() because of the problem you were trying to solve dealing with Hot Observables.
Rafael Guillen
@rguillens
Jun 19 2017 13:50
@i-schuetz , as you may know a cold observable become hot with the publish() operator. refCount() operator returns an Observable<T> that is connected to this hot observable as long as there are subscribers to it. This is intended to prevent unnecessary event processing and propagation, because hot observable sources just keep emitting events, you can't control them.
Rafael Guillen
@rguillens
Jun 19 2017 14:12
@i-shuetz, By the way, the execution of the map() operator for each subscriber doesn't mean that there are two subscriptions. Don't use map, use doOn operators, with doOnSubscribe()you'll see there is only one subscription, but you'll need to change the observable source to something that lasts a little more.
In the code below, the subscription and emission of o1 is so fast, that when o2 is subscribed o1 is already disposed. That's why there are two subscriptions, but one after the other.
Observable<String> source = Observable.just("foo").map(par -> {
            System.out.println("called!"); // executed twice
            return par;
        }).publish().refCount();


        source.subscribe(par -> System.out.println("o1: " + par),
                System.out::println,
                () -> System.out.println("Done!"));

        source.subscribe(par -> System.out.println("o2: " + par),
                System.out::println,
                () -> System.out.println("Done!"));
Joshua Street
@jjstreet
Jun 19 2017 20:50
hello
i have a hopefully straight-forward question about RxJava, specifically about merging completables
Completable.merge() according to docs, subscribes to all specified completables
i want to somehow delay those subscriptions to when the completable created by the merge is subscribed to
and have functionality that is similar to Completable.fromAction
im struggling trying to figure out how to achieve this, any thoughts or ideas?
Joshua Street
@jjstreet
Jun 19 2017 21:16
forget my question i had issues in my test code that lead me to believe an incorrect assumption about how merge worked with subscriptions