1

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 :)

Michal Boska
  • 1,041
  • 1
  • 8
  • 26
  • 1
    Did you check `mergeDelayError`? It's not exactly what you're looking for, but maybe you can sitll use it. Otherwise I guess you'll have to combine some operators yourself to achieve it, probably `map` to convert to `Try`, `catch` to convert the errors to `Failure` and `zip` at the end. Btw instead of using `Try`, you could also use `rx.Notification` and `materialize`. – Samuel Gruetter Jul 18 '15 at 07:11

1 Answers1

3

.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.

Dave Moten
  • 11,957
  • 2
  • 40
  • 47