These are chat archives for ReactiveX/RxJava

20th
Sep 2016
Vasilis Charalampakis
@charbgr
Sep 20 2016 10:27
Hii
is there anyway to get the latest value from an hot Observable event if it has n’t any subscriptions?
This message was deleted
 Observable<String> registAAARObservable = Observable.create(new Observable.OnSubscribe<String>() {
        @Override
        public void call(Subscriber<? super String> subscriber) {
            System.out.println("times");
            subscriber.onNext("REGISTERING");
        }
    }).share();

        Subscription bag = registAAARObservable.subscribe((value) -> System.out.println(value));
        bag.unsubscribe();

        Subscription s1 = registAAARObservable.subscribe((value) -> System.out.println(value));
        s1.unsubscribe();

        Subscription s2 = registAAARObservable.subscribe((value) -> System.out.println(value));
this gives me this output
times
REGISTERING
times
REGISTERING
times
REGISTERING
but i want
times
REGISTERING
REGISTERING
REGISTERING
the problem seems on refCount(internal behavior of share())
Vasilis Charalampakis
@charbgr
Sep 20 2016 10:34
.share().cache()
is a safe option?
Eugene Popovich
@httpdispatch
Sep 20 2016 10:34
@charbgr what about publish-connect, does it work as expected?
Vasilis Charalampakis
@charbgr
Sep 20 2016 10:35
I dont know when to connect()
thats my prob
Dorus
@Dorus
Sep 20 2016 10:35
@charbgr Probably replay(1) and connect to it. Does RxJava have share and cache??
connect activates it, the resulting subscriptions can be used ot manage the lifetime of the shared object
Vasilis Charalampakis
@charbgr
Sep 20 2016 10:36
there is no method PublishReplay
actually it has share() and cache()
Dorus
@Dorus
Sep 20 2016 10:36
Ah found it, just replay(1)
Francisco Estevez
@FranciscoE-Hudl
Sep 20 2016 14:26
is there any reason why the concatenation of two materialized observables would eat up onNext events?
Observable
.concat(
bla().materialize(),
ble().materialize())
.dematerialize();
without materialize/dematerialize they go with onNext and onError, etc
but with them both return only two Complete events
Dorus
@Dorus
Sep 20 2016 14:34
@FranciscoE-Hudl Only thing i can come up with is that the complete from bla will play and then ble cannot continue.
Francisco Estevez
@FranciscoE-Hudl
Sep 20 2016 14:36
but concat is supposed to fix that
Dorus
@Dorus
Sep 20 2016 14:37
How do you expect concat to remove Notification.OnCompleted?
Francisco Estevez
@FranciscoE-Hudl
Sep 20 2016 14:38
hmmmmm
no, what I mean is that I only get the OnCompleted notification
not the onNext or onError ones
before the dematerialize()
Dorus
@Dorus
Sep 20 2016 14:38
That's weird
bla     1----2---3---|
.mat     ---- --- ---
        n(1) n(2)n(3)c()|
ble     4----5------6|
.mat     ---- ------  |
        n(4) n(5)   n(6)
                     c()
.concat  ---- --- ---  ---- ------  |
        n(1) n(2)n(3)c()   n(5)   n(6)
                      n(4)         c()
.demat  1----2---3---|4----5------6|
                     ^oops
That's what i would expect.
Francisco Estevez
@FranciscoE-Hudl
Sep 20 2016 14:45
yeah, found the solution
it required filtering the n(c)
Dorus
@Dorus
Sep 20 2016 14:46
yup, you only need that on the last one.
Probably easiest to concat it :P
Francisco Estevez
@FranciscoE-Hudl
Sep 20 2016 14:47
tests tell me I need it on both
Francisco Estevez
@FranciscoE-Hudl
Sep 20 2016 14:52
it ended up looking like
Observable
.concat(
bla().materialize(),
ble().materialize())
.filter { noti -> noti.kind == OnCompleted }
.dematerialize();
thanks
Toon Sevrin
@toonsevrin
Sep 20 2016 16:37
Also you should probably take a Scheduler and use Scheduler.now() instead of Calendar
Thanks, this is very important for testing :)
@Dorus
Toon Sevrin
@toonsevrin
Sep 20 2016 17:59
Btw, here's my finished code integrated in my project (removes a HUD after XXX display time). Documentation is lacking atm. https://github.com/Exorath/ExoHUD/blob/master/src/main/java/com/exorath/exoHUD/removers/DelayRemover.java