Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJava Observable minimum execution time

I have an Observable (which obtains data from network). The problem is that observable can be fast or slow depending on network conditions.

I show progress widget, when observable is executing, and hide it when observable completes. When the network is fast - progress flikers (appears and disappears). I want to set minimum execution time of observable to 1 second. How can I do that?

"Delay" operator is not an option because it will delay even for slow network.

like image 214
wilddev Avatar asked Jan 05 '23 19:01

wilddev


1 Answers

You can use Observable.zip() for that. Given

Observable<Response> network = ...

One can do

Observable<Integer> readyNotification = Observable.just(42).delay(1, TimeUnit.SECONDS);
Observable delayedNetwork = network.zipWith(readyNotification, 
                                                (response, notUsed) -> response);
like image 113
m.ostroverkhov Avatar answered Jan 17 '23 05:01

m.ostroverkhov