rx-java

How to execute 2 Observables in parallel, ignoring their results and execute next Observable

本小妞迷上赌 提交于 2020-01-24 17:33:29
问题 I have to execute 2 observable in parallel (don't care about their output), and when they both finished -> run another observable. This is my solution, but I feel there are better ones: rx.Observable<GameObject> obs1 = ...; rx.Observable<GameObject> obs2 = ...; rx.Observable.merge(obs1,obs2).takeLast(1) .flatMap(mergeObj -> { return payoutStrategy.calculatePayout(gameTemplate, gameData); }).subscribe(results -> { ... }); I use merge just in order to invoke the 2 obs's and then 'takeLast(1)'

In RxJava, how to retry/resume on error, instead of completing the observable

蓝咒 提交于 2020-01-23 06:30:06
问题 What I want to achieve is: monitor preferences for a certain change when a change is detected, start new network call using the new value transform result display result in UI I know when the change happens, now I presume I need to call onNext on a Subject. This should then trigger a Rx chain, and in the end I can update the UI. mViewPeriodSubject = PublishSubject.create(); mAdapterObservable = mViewPeriodSubject .flatMap(period -> MyRetrofitAPI.getService().fetchData(period)) // this might

RxJava - Combining multiple/different web service calls

偶尔善良 提交于 2020-01-21 12:44:16
问题 I'm working with the Basecamp api to return and display to do lists. Here's a sample of what I'm doing at the moment: bcxClient .fetchToDoLists() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<BcxToDoList>>() { @Override public void call(List<BcxToDoList> bcxToDoLists) { for( final BcxToDoList toDoList : bcxToDoLists ) { bcxClient .fetchToDos( toDoList.bucket.id ) .subscribeOn( Schedulers.io() ) .observeOn( AndroidSchedulers.mainThread() )

RxJava - Combining multiple/different web service calls

别等时光非礼了梦想. 提交于 2020-01-21 12:42:17
问题 I'm working with the Basecamp api to return and display to do lists. Here's a sample of what I'm doing at the moment: bcxClient .fetchToDoLists() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<BcxToDoList>>() { @Override public void call(List<BcxToDoList> bcxToDoLists) { for( final BcxToDoList toDoList : bcxToDoLists ) { bcxClient .fetchToDos( toDoList.bucket.id ) .subscribeOn( Schedulers.io() ) .observeOn( AndroidSchedulers.mainThread() )

Get GoogleMap snapshot on background

一个人想着一个人 提交于 2020-01-21 12:10:30
问题 I'm trying to get the snapshot of a GoogleMap (from MapView) on background, return it with a callback and show it in an ImageView. While doing this, I'm trying to make getting snapshot part independent from the layout as much as possible (so, trying to avoid adding a MapView to the layout). What I've tried was creating a MapView programmatically with given size, adding some paths and pins on it, getting the snapshot and returning it (all subscribed using RxJava) but I'm getting the following

Combining groupBy and flatMap(maxConcurrent, …) in RxJava/RxScala

允我心安 提交于 2020-01-17 07:29:49
问题 I have incoming processing requests, of which I want do not want too many processing concurrently due to depleting shared resources. I also would prefer requests which share some unique key to not be executed concurrently: def process(request: Request): Observable[Answer] = ??? requestsStream .groupBy(request => request.key) .flatMap(maxConcurrentProcessing, { case (key, requestsForKey) => requestsForKey .flatMap(1, process) }) However, the above doesn't work because the observable per key

Will combinelatest trigger doOnUnsubscribe of its children

本秂侑毒 提交于 2020-01-17 05:10:07
问题 Not sure if the combined observable delegates doonunsubscribe to its sources. If not is there a simple way to trigger the unsubscribles of its children? In code: observable o = observable.combinelatest(o1, o2); If something triggers unsubscribe of o will it trigger the unsubscribe of o1 and o2? 回答1: Not sure what you mean. Unsubscription is propagated to both o1 and o2 but if you want to perform custom actions, you have to use doOnUnsubscribe on all relevant parties: Observable<T> o =

RxJava - Debug chain that seems to block forever

喜欢而已 提交于 2020-01-17 04:40:11
问题 I'm running the following code: List<GroupedObservable<BcxToDoList, BcxToDo>> mToDoList; mToDoList = bcxClient .fetchToDos() .flatMap(new Func1<List<BcxToDo>, Observable<BcxToDo>>() { @Override public Observable<BcxToDo> call(List<BcxToDo> bcxToDos) { return Observable.from(bcxToDos); } }) .groupBy(new Func1<BcxToDo, BcxToDoList>() { @Override public BcxToDoList call(BcxToDo bcxToDo) { return bcxToDo.toDoList; } }) .toList() .toBlocking() .single(); When I step into this code in Android

Does take(1) stop the upstream flowable doing work?

梦想与她 提交于 2020-01-16 09:41:10
问题 Let's assume we have some Flowable that looks like: val exampleFlowable = Flowable.create<Int>({ emitter -> while (true) { Thread.sleep(TimeUnit.SECONDS.toMillis(1)) emitter.onNext(1) } }, BackpressureStrategy.LATEST) .subscribeOn(Schedulers.io()) And then I call take(1) on it and subscribe to it like so (notice, disposing of the disposable in the subscribe block): var disposable: Disposable? = null disposable = exampleFlowable.take(1) .observeOn(AndroidSchedulers.mainThread()) .subscribe({

Does take(1) stop the upstream flowable doing work?

主宰稳场 提交于 2020-01-16 09:41:10
问题 Let's assume we have some Flowable that looks like: val exampleFlowable = Flowable.create<Int>({ emitter -> while (true) { Thread.sleep(TimeUnit.SECONDS.toMillis(1)) emitter.onNext(1) } }, BackpressureStrategy.LATEST) .subscribeOn(Schedulers.io()) And then I call take(1) on it and subscribe to it like so (notice, disposing of the disposable in the subscribe block): var disposable: Disposable? = null disposable = exampleFlowable.take(1) .observeOn(AndroidSchedulers.mainThread()) .subscribe({