Observable<Object> o = Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(@NotNull ObservableEmitter<Object> emitter) throws Exception {
emitter.onNext("发送接受");
emitter.onComplete();
}
});
o.flatMap(new Function<Object, ObservableSource<String>>() {
@Override
public ObservableSource<String> apply(@NotNull Object o) throws Exception {
return Observable.just("1111");
}
}).subscribe(new Observer<String>() {
@Override
public void onSubscribe(@NotNull Disposable d) {
}
@Override
public void onNext(@NotNull String s) {
System.out.println(s);
}
@Override
public void onError(@NotNull Throwable e) {
}
@Override
public void onComplete() {
System.out.println("onComplete");
}
});
}
打印消息
1111
onComplete
当你把 o中的
emitter.onNext("发送接受");
删除,你将只能收到 打印消息
onComplete