public static void subscribe(Observable<String> o) { o = o.materialize().flatMap(n -> { if (n.isOnError()) { if (n.getThrowable() instanceof IllegalStateException) { return Observable.just(n); } else { return Observable.error(n.getThrowable()); } } else { return Observable.just(n); } }).retry().dematerialize(); o.subscribe(System.out::println, t -> t.printStackTrace()); } }
@Override public Observable<?> call(Observable<? extends Notification<?>> ts) { return ts.map(new Func1<Notification<?>, Notification<?>>() { int num=0; @Override public Notification<?> call(Notification<?> terminalNotification) { if(count == 0) { return terminalNotification; } num++; if(num <= count) { return Notification.createOnNext(num); } else { return terminalNotification; } } }).dematerialize(); } }
@Override public void run() { Observable o1 = Observable.range(1, 3).materialize(); o1.subscribe(new Action1<Notification<Integer>>() { @Override public void call(Notification<Integer> integerNotification) { log("******"); log("kind:" + integerNotification.getKind()); log("value:" + integerNotification.getValue()); } }); o1.dematerialize().subscribe(new Action1() { @Override public void call(Object o) { log(o.toString()); } }); } });
@Override public Observable<Out> call() { Mutable<State> state = new Mutable<State>(initialState.call()); return source.materialize() // do state transitions and emit notifications // use flatMap to emit notification values .flatMap(execute(transition, completion, state, backpressureStrategy), initialRequest) // complete if we encounter an unsubscribed sentinel .takeWhile(NOT_UNSUBSCRIBED) // flatten notifications to a stream which will enable // early termination from the state machine if desired .dematerialize(); } });
@Override public Observable<Out> call() { Mutable<State> state = new Mutable<State>(initialState.call()); return source.materialize() // do state transitions and emit notifications // use flatMap to emit notification values .flatMap(execute(transition, completion, state, backpressureStrategy), initialRequest) // complete if we encounter an unsubscribed sentinel .takeWhile(NOT_UNSUBSCRIBED) // flatten notifications to a stream which will enable // early termination from the state machine if desired .dematerialize(); } });