These are chat archives for ReactiveX/RxJava

18th
Aug 2018
Ignacio Baca Moreno-Torres
@ibaca
Aug 18 2018 07:14
@ylecaillez you can use publish and merge the take(1) with a ignoreElements, so the source observable keep subscribe untils it completes (you can exgract the compose lamda to reuse the operator)
Observable.just(1, 2, 3).doOnNext(n -> out.println("emmit " + n))
        .compose(o -> o.publish(p -> p.take(1)))
        .subscribe(n -> out.println("final " + n));
// emmit 1 ⏎ final 1
Observable.just(1, 2, 3).doOnNext(n -> out.println("emmit " + n))
        .compose(o -> o.publish(p -> p.take(1).mergeWith(p.ignoreElements())))
        .subscribe(n -> out.println("final " + n));
// emmit 1 ⏎ final 1 ⏎ emmit 2 ⏎ emmit 3