java - RxJava error handling -
i have method creates , merges 2 observable<t>
's.
private observable<string> getdata() { observable<string> observable1 = observable.just("just string") .delay(2, timeunit.seconds); observable<string> observable2 = observable.create(new observable.onsubscribe<string>() { @override public void call(subscriber<? super string> subscriber) { subscriber.onerror(new exception("oops!")); } }); observable<string> merged = observable1.mergewith(observable2); return merged; }
the problem error in observable2
emitted earlier data in observable1
.
getdata().subscribe(new observer<string>() { @override public void oncompleted() { log.d("rx", "oncompleted"); } @override public void onerror(throwable e) { log.d("rx", "onerror: " + e.getmessage()); } @override public void onnext(string s) { log.d("rx", "onnext: " + s); } });
observable2
emitted optional data , errors observable2
must not terminate emission, on other hand, want handle errors , data in single observer. can return error after result observable1
? possible?
expect results:
onnext: string onerror: oops!
sounds need observable.mergedelayerror()
.
it applies merge
operation if of observables call onerror
, doesn't stop right away captures error(s).
once other observables have gracefully completed, error(s) is(are) propagated, potentially combined single compositeexception
.
Comments
Post a Comment