问题描述
我想使用 RxJS 的 onErrorResumeNext
特性,即即使收到错误也继续接收事件(而不是终止).
I would like to use the onErrorResumeNext
feature of RxJS, i.e. to continue to receive events even if an error is received (instead of terminating).
但我可以在以下文档中看到 RxJS5 中没有对应关系:https://github.com/ReactiveX/RxJS/blob/master/MIGRATION.md.
But I can see in the following doc that there is no correspondance in RxJS5: https://github.com/ReactiveX/RxJS/blob/master/MIGRATION.md.
是否有使用此类功能的解决方法?谢谢!
Is there a workaround to use such feature?Thanks!
推荐答案
我也一直在寻找那个运营商!我想出了一个满足我需求的解决方案,希望对您有所帮助.这不是最有可能的最佳解决方案,但我希望它能有所帮助,直到其他人在这里找到更好的解决方案,或者直到在 5.0 中重新添加此运算符(希望如此!):)
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 示例:https://jsbin.com/qadozoveta/edit?html,js,控制台
这篇关于如何在 RxJS5 中恢复 OnError(或类似)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!