Category : rx-java

I have three classes, Point, Polygon and Elipse that inherit from Shape class. I retrieve them from Room database using LiveData. I have a MainViewModel that calls the three view models corresponding to each shape, and converting the LiveData to a Flowable, this is the code in the MainViewModel: var mergedViewModelsLiveData: Flowable<List<Shape>> =Flowable.merge( LiveDataReactiveStreams.toPublisher(appCompatActivity, pointViewModel.getAllPoints()), ..

Read more

This is a scenario I’m having. I’ve two methods getCachedData(): Single<Optional> getRemoteData(): Single Now what I want to know is how to write a function like getData(): Single<Custom>, which will fetch this Custom data from cache. If the cache doesn’t have it, I would like to fetch the same from remote. I also don’t want ..

Read more

Let’s say I have an Android app with the following Repository class to fetch objects from API: override fun fetchOrderById(orderId: Long): Single<List<ItemRow>> { return api.fetchOrderByIdObservable(orderId) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .map { orderResponse -> orderResponse.items.map { deliveryItem -> deliveryItem.asItemRow() } } } override fun fetchOrders(): Single<OrdersResponse> { return api.fetchOrdersObservable() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) } override fun fetchAllOrders(): Single<List<ItemRow>> { // ..

Read more

Expected: Given one Single and multiple Completable, return a completable. Result: Cannot resolve method ‘merge(io.reactivex.rxjava3.core.Completable, io.reactivex.rxjava3.core.Completable, io.reactivex.rxjava3.core.Completable)’ I’m currently trying to set up a flow for registering a user. However, I can’t seem to find any documentation about mapping a Single’s result to a set of completable. The idea here is create a user in ..

Read more

I face a problem with rxJava interval when some method throws an exception interval stop working. For continued work, I add retryWhen() operator but this does not work? How to resume work when an error/exception happens? Flowable.interval( 0, Constants.INTERVAL, TimeUnit.MILLISECONDS, Schedulers.io() ).map { prepareData() } .flatMap { sendRequestToServer() } .retryWhen { flowable -> flowable.delay(Constants.RETRY_ON_FAILURE_TIME, TimeUnit.MICROSECONDS) ..

Read more