rx-java2

Using flatMap in RxJava 2.x

戏子无情 提交于 2020-01-01 11:58:11
问题 I'm working with an API of my own and a i'm hoping to chain a few paginated results using RxJava. I use cursor based pagination. (imagine there are 50 users in this first request): { "data":{ "status":"ok", "total":988, //users total "has_next_page":true, "end_cursor":"AQAxd8QPGHum7LSDz8DnwIh7yHJDM22nEjd", "users":[{"id":"91273813", "username":"codergirl", "full_name":"Code Girl", "picture_url":"https://cdn.com/21603182_7904715668509949952_n.jpg", }, ... ] } } Right now, I'm getting the first

RxJava 2 / Retrofit 2 - NetworkOnMainThreadException

空扰寡人 提交于 2019-12-30 06:43:06
问题 I need to perform a request, if my token is expired I need to refresh it and retry the request. This is how I'm trying to do it, at the moment I can refresh the token but it throws me a NetworkOnMainThreadException. It finishes the request,update the token and reaches logs, but that exception its killing me. How can I avoid that? public Observable<Estabelecimento> listarEstabelecimentos() { return Observable.defer(this::getListarEstabelecimentoObservable) .retryWhen(throwableObservable ->

Android RXJava2 memory performance

≡放荡痞女 提交于 2019-12-25 17:42:48
问题 I created an Observable(RxJava2 + Volley) that repeat for each 5 seconds, It works but when I Dump Java Heap(memory),there are many Instance of my Model JAVA class,and it will increase for each time that the Observable get repeating. Why RX create several instance of my model? How can I use only ONE instance of it? Model public RequestFuture<String> getLiveRefreshFuture() { RequestFuture<String> future = RequestFuture.newFuture(); VolleyStringRequest request = new VolleyStringRequest(Request

RxJava Observable.create wrapping observable subscriptions

亡梦爱人 提交于 2019-12-25 09:27:31
问题 I used Observable.create so I could notify the subscriber when certain data was available. I am a little uncertain of subscribing to observables inside of my create method. Are these nested subscriptions going to give me any sort of issue? I'm not completely familiar with creating observables using Observable.create so I wanted to make sure I'm not doing anything out of the ordinary or misusing it. Thank you in advance! abstract class NetworkResource<ApiType, DbType> constructor(private val

Polling using RXJava2 / RXAndroid 2 and Retrofit

大城市里の小女人 提交于 2019-12-25 09:15:32
问题 i would like to implement a Pollingservice which calls a REST Api every nDelay Seconds and notify all subscribers if the data has been changed. Now i have a little problem with my code since it always returns a value to my Consumer, even if the data has not been changed. private Observable<List<HueLight>> pollingLightsObservable = null; public Observable<List<HueLight>> getPollingLightsObservable() { if (pollingLightsObservable == null) { pollingLightsObservable = Observable.fromCallable( ()

Null handling in rx-java2 flatMap

删除回忆录丶 提交于 2019-12-25 08:59:24
问题 As explained in the docs RxJava 2.x no longer accepts null values. So it is not surprising that both of the following two lines terminate with onError called: Observable.fromCallable(() -> null); Observable.just(1).flatMap(i -> Observable.error(new RuntimeException())); what is unclear is why Observable.just(1).flatMap(i -> Observable.fromCallable(() -> null)) terminates with success and no items emitted. It seams reasonable to expect for it behave in the same fashion as Observable.error I

RxJava 2: always unsubscribe on the .subscribeOn(..) scheduler?

白昼怎懂夜的黑 提交于 2019-12-25 08:15:42
问题 I have an Observable<String> that performs some work. After its done, it closes its connections (via .setDisposable(Disposables.fromAction(logic*); . Trouble is, I need this close action to be performed on the same scheduler as the actual workload. Is it possible? How? I dont want to force the Observable to perform on a given scheduler, e.g. myObservable.subscribeOn(x).unsubscribeOn(x); ; 回答1: You need a single threaded scheduler for that to work and you can get one via Schedulers.from

Is it ok to transform following code in rxjava

心不动则不痛 提交于 2019-12-25 07:58:48
问题 For example, I have following runnable java code. It is about a producer and several parallel consumers. These consumers are running time consuming jobs, and they are running in parallel. I wonder if this use case match rx-java, and how to rewrite it in rx-java. public class DemoInJava { public static void main(String[] args) { final BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(); AtomicBoolean done = new AtomicBoolean(false); Thread producer = new Thread(() -> { int offset = 0;

RxJava 2 doesn't tell the error line

送分小仙女□ 提交于 2019-12-25 05:36:19
问题 It seems to me that RxJava doesn't give good exception tracing. One example is this which I got from Eclipse when running my unit test. It is not clear which code using the map function. Is there any special trick to increase the tracing ability? Or is this considered as a bug? 2017-02-28 19:12:44/SGT INFO c.bt.nmdb.ndac.adapter.Bnmpv5Adapter : Current time stamp - Tue Dec 23 23:56:00 SGT 2014 2017-02-28 19:12:45/SGT TRACE c.bt.nmdb.ndac.adapter.Bnmpv5Adapter : @findAndSendDeviceCredentials()

RxJava/RxKotlin: combineLatest that already completes if one source completes (not all)

泄露秘密 提交于 2019-12-25 04:19:20
问题 Basically, I have two Flowables F and G and I want to use combineLatest on them, but I want the combined Flowable to already complete if F completes (even if G is still running). Here is an example of what I what to achieve with an ugly solution: fun combineFandGbutTerminateIfFTerminates(F: Flowable<Int>, G: Flowable<Int>) : Flowable<Pair<Int, Int>> { val _F = F.share() val _G = G.takeUntil(_F.ignoreElements().toFlowable<Nothing>()) val FandG = Flowables.combineLatest(_F, _G) return FandG }