Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Correct use of Single with control flow in RxJava2

Tags: flow correctly


I have the following Rx chain in my code:

public Single> dispatchStuff(){
return mRepository.getList()
.filter(list -> list.size() != 0)

However, I'm not sure I'm using the filtering Correctly here. The getList() method will always return a value or error, therefore I think using Single is acceptable. However, then I want to perform other operations only if there are elements in the list returned. If I filter Single and my list size is 0, it will through an exception:

at io.reactivex.internal.operators.maybe.MaybeFlatMapSingle$FlatMapMaybeObserver.onComplete(
at io.reactivex.internal.operators.maybe.MaybeFilterSingle$FilterMaybeObserver.onSuccess(
at io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(
at io.reactivex.Single.subscribe(
at io.reactivex.internal.operators.maybe.MaybeFilterSingle.subscribeActual(
at io.reactivex.Maybe.subscribe(
at io.reactivex.internal.operators.maybe.MaybeFlatMapSingle.subscribeActual(
at io.reactivex.Single.subscribe(
at io.reactivex.internal.operators.single.SingleDoOnSuccess.subscribeActual(
at io.reactivex.Single.subscribe(
at io.reactivex.internal.operators.single.SingleSubscribeOn$
at io.reactivex.Scheduler$
at java.util.concurrent.ScheduledThreadPoolExecutor$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$

How should I correctly implement this control Flow when I'm working with Single?

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Correct use of Single with control flow in RxJava2


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription