rx-java2

RxJava group two responses one of which might be NULL with zip operator

北慕城南 提交于 2019-12-25 02:33:00
问题 I want to make two concurent request to Realm database and return results with RxJava. The issue is that one of requests can return NULL object and I have a crash. How can I properly return results from both DB even if one of them NULL? Thanks. public void getDataFromTwoSources(DisposableObserver<ComplexUserDto> observer, String shopId) { Preconditions.checkNotNull(observer); final Observable<ComplexUserDto> observable = Observable.zip(firstRepository.getUserData(userId), secondRepository

Using `onBackpressureLatest` to drop intermediate messages in blocking Flowable

你。 提交于 2019-12-25 00:26:31
问题 I have a chain where I do some blocking IO calls (e.g. HTTP-call). I want the blocking call to consume a value, proceed without interrupting, but drop everything that is piling up meanwhile, and then consume the next value in the same manner. Consider the following example: fun main() { Flowable.interval(100, TimeUnit.MILLISECONDS).onBackpressureLatest().map { Thread.sleep(1000) it }.blockingForEach { println(it) } } From a naive point of view, I would it expect to print something like 0, 10,

RxJava order of execution confusion

旧城冷巷雨未停 提交于 2019-12-25 00:24:00
问题 I have this very simple RxJava example List<Integer> arrayIntegers = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); Observable.fromIterable(arrayIntegers).map(i -> { Log.d("RxJava", "map i = " + i); return i; }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()). subscribe(new DisposableObserver<Integer>() { @Override public void onNext(Integer i) { Log.d("RxJava", "next i = " + i); } @Override public void onError(Throwable e) {} @Override public void onComplete() {

How to mock EntityBus.rxSend()

断了今生、忘了曾经 提交于 2019-12-25 00:05:52
问题 The io.vertx.reactivex.core.eventbus.EventBus.rxSend() method has the following signature: public <T> Single<Message<T>> rxSend(String address, Object message, DeliveryOptions options) What is the correct way to mock this so that it returns a Single containing a real object? The issue is that the Message class has no constructor apart from one which which takes another Message object. So the following will compile: Mockito.when(eventBus.rxSend(Mockito.isA(String.class), Mockito.isA(JsonObject

JavaRX Pagination - observe in each interration rather than at the end - Generic Paginator

≡放荡痞女 提交于 2019-12-24 19:08:23
问题 I'm working with a paginated API. I have used the following solution provided by Adam Millerchip and it works well. import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.function.Function; import io.reactivex.Flowable; import io.reactivex.Single; import io.reactivex.processors.BehaviorProcessor; public class Pagination { // Fetch all pages and return the items contained in those pages, using the provided page fetcher function

If it safe to have blocking operation inside flatMap { … } mapper function?

不羁的心 提交于 2019-12-24 17:52:37
问题 I'd like to organize a thread barrier: given a single lock object, any thread can obtain it and continue thread's chain further, but any other thread will stay dormant on the same lock object until the first thread finishes and releases the lock. Let's express my intention in code (log() simply prints string in a log): val mutex = Semaphore(1) // number of permits is 1 source .subscribeOn(Schedulers.newThread()) // any unbound scheduler (io, newThread) .flatMap { log("#1") mutex

If is toBlockingFirst method reliable?

那年仲夏 提交于 2019-12-24 15:27:45
问题 My question about the method toBlockingFirst() . Is it a reliable method? i.e. Can I get InterruptedException with crash if I call dispose for disposable from subscrine? for example: .flatMap{ host -> val count = userRepository.getUsers(PrefProvider.currentTourCode) .map { it.size } .blockingFirst() if (count>2) { callSomething() } else { callElse() } } Can someone to explain me please? 回答1: If flatMap runs on an RxJava Scheduler the time blockingFirst is invoked, you'll likely get an

RecyclerView item click using RxJava2 + RxBinding not working after Fragment replacements

房东的猫 提交于 2019-12-24 09:36:02
问题 I have a RecyclerView in Fragment, item clicks are handled using RxJava2 as explained in this SO answer, It's working fine in non fragments. private PublishSubject<Place> itemViewClickSubject = PublishSubject.create(); @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.search_result_view, parent, false); ViewHolder viewHolder = new ViewHolder(view); // convert click events into reactive stream

RxJava2 + Room: data is not being inserted in DB after clearAllTables() call

瘦欲@ 提交于 2019-12-24 08:26:15
问题 In my Android application after successful login I'm saving session info in Room, then I'm retrieving user information from BE and saving it too. Everything works fine. I can see saved information in database tables. When user logs out from application all tables are being cleared with appDatabase.clearAllTables() method call. The catch is that on subsequent login there's no information that is being inserted in DB but my Rx calls aren't throwing any errors. I've tried to use logging and

OkHttp Authenticator sometimes does not call authenticate on HTTP 401

流过昼夜 提交于 2019-12-24 08:25:32
问题 I have an issue that OkHttp 's Authenticator does not call the authenticate method in some cases of HTTP 401 errors. Interceptors are always called, but authenticator is sometimes called and sometimes not. Once it does not call it it will not call it for several minutes and all network calls will fail with HTTP 401. Then after 5-6 minutes it will "unstuck" and call the authenticate method again. I use it for refreshing token. If the token expiration is set to one hour, there are no issues,