Is there anything in RxJava similar to this? <http...
# rx
i
Is there anything in RxJava similar to this? https://github.com/ReactiveX/RxSwift/blob/master/Documentation/Traits.md#driver More specifically
Can't error out
I'd like that e.g. if I map a click button trigger to an api request an the api request fails, it executes again the next time the trigger is activated. Without having to create a new subscription each time.
m
onErrorReturn
onErrorReturnItem
p
RxRelay
might be what you want
i
@magnumrocha
onErrorReturn
and
onErrorReturnItem
still cancel the stream
@pt but relay doesn't have any error handling at all, right? My streams can fail. I just want to be able to continue listening after it.
hmm I guess I could convert the inner
Single
to a
Result
or something... it's just not as convenient as
Driver
Driver
is like
LiveData
, but it recovers from errors
m
@iex to avoid your stream finish, you can combine it with
flatMap
(in case of Single) or `switchMap`:
Copy code
disposable = reactiveLocationProvider.getUpdatedLocation(mLocationRequest)
        .buffer(50)
        .flatMap(locations -> mRestService.postLocations(locations).onErrorReturn { e -> emptyList() }
        .subscribeOn(Schedulers.newThread())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe()
i
yeah, I'm aware that it's possible to nest the failable observable and recover from it. Hmm
It's behaves similarly to driver actually, just a bit less nice to use
I guess the nested observable can also be made to return
empty()
or similar
if you don't have a meaningful fallback
m
sure, this will depends of your business logic...
i
ok, thanks @magnumrocha
👍 1