我想合并/合并多个观察对象当他们每个完成时执行一个最后函数。 merge
运营商似乎并行执行每个订阅,这是我需要的,但如果他们中的任何一个抛出一个错误执行被暂停。rxjs5合并和错误处理
RxJS 4版有一个运营商mergeDelayError应该继续执行,直到所有的人都完成了所有订阅,但该运营商不版本5实现。
我应该回到不同的操作员吗?
var source1 = Rx.Observable.of(1,2,3).delay(3000);
var source2 = Rx.Observable.throw(new Error('woops'));
var source3 = Rx.Observable.of(4,5,6).delay(1000);
// Combine the 3 sources into 1
var source = Rx.Observable
.merge(source1, source2, source3)
.finally(() => {
// finally is executed before all
// subscriptions are completed.
console.log('finally');
});
var subscription = source.subscribe(
x => console.log('next:', x),
e => console.log('error:', e),
() => console.log('completed'));
JSBin
谢谢 - 'catch'似乎不起作用。相反,我只是用'onErrorResumeNext'映射了所有东西,这在我的情况下是可以的。 – null
@null catch()运算符不起作用如何?我认为它应该工作... – martin
我不知道为什么。看到这个JSBin:[http://jsbin.com/qaluyaq/edit?js,console](http://jsbin.com/qaluyaq/edit?js,console) – null