Skip to content

Instantly share code, notes, and snippets.

@ZherebtsovAlexandr
Created December 8, 2016 11:35
Show Gist options
  • Save ZherebtsovAlexandr/7349314049a88cbc38ed11e170bdd7f1 to your computer and use it in GitHub Desktop.
Save ZherebtsovAlexandr/7349314049a88cbc38ed11e170bdd7f1 to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String[] args) {
final Emitter<String>[] emitter = new Emitter[]{null};
Observable<Integer> integerObservable = Observable.just(0, 1, 2, 3, 4)
.concatMap(integer -> {
if (emitter[0] != null) {
emitter[0].onCompleted();
}
return Observable.just(integer);
});
Observable<String> result = integerObservable.concatMap(integer ->
Observable.fromEmitter(
(Action1<Emitter<String>>) stringEmitter -> {
emitter[0] = stringEmitter;
stringEmitter.onNext("Result: " + integer);
}, Emitter.BackpressureMode.BUFFER)
);
result.subscribe(s -> System.out.println(s));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment