How to resumeOnError (or similar) in RxJS5

拜拜、爱过 提交于 2019-12-06 05:01:52

I've been looking for that operator too! I came up with a solution for my needs that I hope will help yours. It's not the best solution most likely, but I hope it can help until a better solution can be found by some others on here, or until this operator is added back in 5.0 (hopefully!) :)

var Observable = Rx.Observable;

var source1 = Observable.create(function(observer){
    observer.error();
});
var source2 = Observable.create(function(observer){
    observer.next('Continuing on');
    observer.complete();
});


var stream = source1.catch(function(data){
  return source2;
});



stream.subscribe(function(data){
  console.log(data);
});

JS Bin Example: https://jsbin.com/qadozoveta/edit?html,js,console

You can use the following in rxjs5 still.

 Observable.onErrorResumeNext(observable1$, observable2$, observable3$...)
           .subscribe(() => { ... })

onErrorResumeNext source code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!