'mergeDelayError'在RxJS 5中不存在

问题描述 投票:5回答:1

我在RxJS 4中遇到了这种方法,它似乎很有帮助,但是我似乎在RxJS 5的任何地方都找不到它。

https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/errors.md

有人知道RxJS 5中是否有类似行为?

rxjs rxjs5
1个回答
0
投票

您可以像这样添加一个polyfill。

function mergeDelayError(...sources: Array<Observable<any>>) {
    const final = new Subject();
    const catching = sources.map(obs => obs.pipe(
        catchError(e => {
            if (!final.hasError) {
                final.error(e);
            }
            return EMPTY;
        }),
    ));

    return concat(merge(...catching), final);
}

const o1$ = interval(150).pipe(take(5));
const o2$ = throwError(new Error('woops1'));
const o3$ = throwError(new Error('woops2'));

mergeDelayError(o1$, o2$, o3$).subscribe(
    x => console.log('next:', x),
    e => console.log('error:', e),
    () => console.log('completed'),
);

输出是

[Log] next: – 0
[Log] next: – 1
[Log] next: – 2
[Log] next: – 3
[Log] next: – 4
[Log] error: – Error: woops1
© www.soinside.com 2019 - 2024. All rights reserved.