我有四个Http Url,我需要一个一个地尝试。但是有一个问题,当其中一个url错误时,后面的url不被调用。伪代码是这样的: i = 0;
Observable.fromArray("http://www.baidu.com/", "http://www.google.com/", "https://www.bing.com/")
.concatMap(new Function<String, ObservableSource<String>>() {
@Override
public ObservableSource<String> apply(String s) throws Exception {
return Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
Log.i("settingsubscribe", i + "");
if (i == 1) {
emitter.onError(new Throwable("error"));
//emitter.onComplete();
} else {
emitter.onNext(s.concat("_1"));
emitter.onComplete();
}
i ++;
}
});
}
})
.subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
Log.i("settingfffff", s);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Log.i("settingfffff", throwable.getMessage());
}
}, new Action() {
@Override
public void run() throws Exception {
Log.i("settingfffff", "onComplete");
}
});
当我= 1时,发送错误并且事件停止,我希望继续,该怎么办?
答案 0 :(得分:0)
emitter.onError(new Throwable("error"));
在上面的代码行onError中,您正在创建新的Throwable,而是可以记录错误