These are chat archives for ReactiveX/RxJava

11th
Dec 2015
Javier Domingo Cansino
@txomon
Dec 11 2015 12:54
So, I have a new usecase, I have a UI that when the user updates it, changes reflect after 2-3 seconds. Now I have a instant refresh, so the UI will get updated every 0.2 secs, regardless on whether the user has changed a value or not, therefore giving a weird user experience
My idea was to: Merge all the inputs as observables, and use them as UI update disabler, then use a delay for 3 seconds, and make it updatable again
the problem is that I have no idea on how to discard previous delays
this is
Javier Domingo Cansino
@txomon
Dec 11 2015 12:59
Observable.merge(a,b,c,d).doOnEach(disableUIUpdates()).delay(3, TimeUnit.SECONDS).subscribe(enableUIUpdates())
the problem is that I don't know how to discard delays and just maintain the last one
I think debounce is what I am looking for
Dorus
@Dorus
Dec 11 2015 13:25
You should ask this question on the Rx.NET gitter. LeeCampbell there has a lot of experience with those kind of questions.
Javier Domingo Cansino
@txomon
Dec 11 2015 13:25
@Dorus solved
it was with debounce indeed
Dorus
@Dorus
Dec 11 2015 13:25
My first tought would be Throttle. That's indeed debouce in RxJava
Ah good :)
Javier Domingo Cansino
@txomon
Dec 11 2015 13:26
Observable
    .merge(a,b,c,d,e)
    .onBackpressureDrop((Object o) -> Log.d(TAG, "Dropped item " + o))
    .doOnEach(new Action1<Notification>() {
        @Override
        public void call(Notification notification) {
        uiIsUpdatable = false;
        }
    })
    .debounce(3, TimeUnit.SECONDS)
    .subscribe(new Observer() {
       @Override
       public void onCompleted() {}
       @Override
       public void onError(Throwable e) {
            Log.e(TAG, "Error on uiDisabler logic", e);
       }
      @Override
       public void onNext(Object o) {
            uiIsUpdatable = true;
       }
    })
Dorus
@Dorus
Dec 11 2015 13:29
Is backpressure relevant when you use debounce?
In fact, debounce might silently discard items here.
Javier Domingo Cansino
@txomon
Dec 11 2015 13:30
I don't think so, but just in case... I add that by default, just in case
Dorus
@Dorus
Dec 11 2015 13:31
in fact, i dont see how backpressure can even appear, all your onnext does is set a variable to true.
Javier Domingo Cansino
@txomon
Dec 11 2015 13:32
@Dorus i am always afraid that pipelines will be too long and will collapse, so I add that as a security measure... the stack is 16 at the end
Dorus
@Dorus
Dec 11 2015 13:32
ah right
looks correct to me otherwise
Another option would be to use Sample.
Javier Domingo Cansino
@txomon
Dec 11 2015 13:35
why sample?
Dorus
@Dorus
Dec 11 2015 13:35
With Sample you would tell the UI when to update.
instead of when not
That's sometimes required if there's a constant stream of input
and Debounce would never yield
Javier Domingo Cansino
@txomon
Dec 11 2015 13:36
ah, but I am not telling it when to update, that's another one, I mean, it's another module the one that calls for UI updates
Dorus
@Dorus
Dec 11 2015 13:36
Just an alternative to consider :) Probably not what you need in this usecase
Javier Domingo Cansino
@txomon
Dec 11 2015 13:36
That would be made if I used Rx to launch the updates sure