Thursday, 18 April 2019

Observable is canceled by flatmapped flowable error

I have the following RxJava2 chain:

fun refreshList() {
        refreshDisposable?.dispose()
        refreshDisposable =
                mapHandler.filtersFlowable()
                        .doOnNext{
                            Timber.w("LISTFILTER - New filter! $it")
                        }
                        .switchMap {
                            lastPage = 0
                            refreshByPage(lastPage, it).toFlowable()
                        }
                        .doOnSubscribe {
                            Timber.w("LISTFILTER - In progress")
                            listRefreshState.postValue(Result.inProgress())
                        }
                        .map {
                            Result.success(it)
                        }
                        .ioUi(schedulerProvider)
                        .subscribeBy(
                                onNext = {
                                    Timber.w("LISTFILTER - Success!")
                                    listRefreshState.value = it
                                },
                                onError = {
                                    Timber.w("LISTFILTER - Error! ${it.message}")
                                    listRefreshState.value = Result.failure(it)
                                }
                        )
                        .addTo(disposables)

    }

That is, i have a set of filters in my app, when you change them a new request should be thrown against the backend API.

Now I found that sometimes the request would fail, and then my filtersFlowable would stop emitting. I would expect for it to keep emitting after changing the filters again.

This is the definition of FiltersFlowable:

private val filterSubject: BehaviorSubject<ApplyFilterRequest> =
        BehaviorSubject.createDefault(
                if (sharedPrefsManager.getFilters().isNotEmpty())
                    ApplyFilterRequest.fromJson(moshi, sharedPrefsManager.getFilters())
                else
                    ApplyFilterRequest.allPlacesAllTypes())

private val filterFlowable = filterSubject.hide().toFlowable(BackpressureStrategy.LATEST)

How can I achieve the desired behavior?



from Observable is canceled by flatmapped flowable error

No comments:

Post a Comment