Michal Boska
Michal Boska

Reputation: 1041

RxJava Observable continue on error and get status

In RxJava (or RX in general), is there any way to combine observables in a way that the resulting observable waits until every observables are finished in either way (does not freak out when any of them throws error) and then complete with a single result containing an information about which observable finished successfully and which encountered an error?

It would additionally return observable's result, if it completed successfully, or an error cause (such as Throwable instance) when completed with failure?

The behavior would be similar to this (RSVP.js):

https://github.com/tildeio/rsvp.js/#all-settled-and-hash-settled

I could optionally implement a concept similar to Scala's Try, wrap values emitted by such observables into Try values and use http://reactivex.io/documentation/operators/catch.html to handle errors and convert them to Error values... but that would be manual work and hence i wanted to know if there is some pre-made operator for this which i missed or didn't understand correctly when reading the documentation

EDIT: It doesn't need to be a single result, I would go with observable that emits all values wrapped in Try constructs as well :)

Upvotes: 1

Views: 565

Answers (1)

Dave Moten
Dave Moten

Reputation: 12087

.materialize() may be what you are looking for. It converts Observable<T> into Observable<Notification<T>> where a Notification is either a value or error or completion.

Upvotes: 3

Related Questions