asynchronous - rxjava - Combine onerror and timout handling -


i start want achieve.

  • i want call method returns observabe.
  • i not know if called method handles exceptions , timeouts
  • i want combine observables in call (merge/zip etc)
  • if 1 method fails, want answers methods succeeded - don't want break flow.

in case of exception, capable of handling , continuing flow, when try add timeoutmanagement fail.

here code

public static void main(string[] args) {     createobservables(false, true); // stalls timeout     zip(); } private static void createobservables(final boolean throwexception,                                        final boolean stall) {     obs1 = observable.just(1);     obs1 = obs1.map(new func1<integer, integer>() {         @override public integer call(integer integer) {             int = 0;             if (throwexception)                 getobj().equals("");             if (stall)                 zzz(10);             return ++integer;         }     });    obs2 = observable.just(111); }  private static void zip() {     system.out.println("**zip**");      obs1 = obs1.onerrorreturn(new func1<throwable, integer>() {         @override public integer call(throwable throwable) {             return 999;         }     });      obs1 = obs1.timeout(5, timeunit.seconds);      observable.zip(obs1, obs2, new func2<integer, integer, arraylist<integer>>() {         @override         public arraylist<integer> call(integer integer1, integer integer2) {             arraylist<integer> integers = new arraylist<integer>();             integers.add(integer1);             integers.add(integer2);             return integers;         }     }).subscribe(new observer<object>() {....}     ); } 

now, when call

createobservables(false , false);  // no exceptions , timeouts  

i onnext - [2, 111].
call

createobservables(true, false);  // throw exception in 1 method  

i onnext - [999, 111] - want. exception , result second method. when call

createobservables(false, true); // stall on timeout  

i onerror.
want other method answer.
thanks.

try creating observable timeout value, in case want same value error case:

observable obs1timeout = observable.just(999); 

then in timeout policy give observable fallback use in case of timeout:

obs1 = obs1.timeout(5, timeunit.seconds, obs1timeout); 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -