我正在压缩三个 observable,三个 observable 中的每一个都有自己的“成功”回调,使用.pipe(tap() => {...});
. 当所有三个 observables 都没有错误地执行时,这可以正常工作,但是如果 observables 之一出错,那么所有的 tap 方法都不会执行。如果该 observable 成功运行,我怎样才能让 tap 方法始终执行?
var request1 = Observable.create(...); //Pretend this one will fail (though request2 or request3 could also fail)
var request2 = Observable.create(...);
var request3 = Observable.create(...);
request1.pipe(tap(() => {
//Unique success callback should always run if request1 succeeds, even if request2 or request 3 fails.
}));
request2.pipe(tap(() => {
//Unique success callback should always run if request2 succeeds, even if request1 or request 3 fails.
}));
request3.pipe(tap(() => {
//Unique success callback should always run if request3 succeeds, even if request1 or request 2 fails.
}));
var observable = zip(request1, request2, request3);
observable.subscribe(() => {
//Do something when all three execute successfully
});