https://kotlinlang.org logo
#rx
Title
# rx
i

iex

03/25/2020, 1:55 PM
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

magnumrocha

03/25/2020, 2:04 PM
onErrorReturn
onErrorReturnItem
p

pt

03/25/2020, 10:04 PM
RxRelay
might be what you want
i

iex

03/26/2020, 6:10 AM
@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

magnumrocha

03/26/2020, 8:24 AM
@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

iex

03/26/2020, 8:32 AM
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

magnumrocha

03/26/2020, 8:36 AM
sure, this will depends of your business logic...
i

iex

03/27/2020, 1:50 PM
ok, thanks @magnumrocha
👍 1
3 Views