Created
December 8, 2016 11:35
-
-
Save ZherebtsovAlexandr/7349314049a88cbc38ed11e170bdd7f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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