在没有错误的情况下,如何 运行 RxJS 链中的一些代码
How to run some code in an RxJS chain given there were no errors
我正在尝试找到一种方法来 运行 只有在给定的 rxjs 链中没有错误的情况下才能编写一些代码。考虑以下问题,在 rxjs 中是否有类似人工 NO_ERROR_OCCURED_RUN_HAPPY_PATH_CODE
运算符的东西?
private wrap(obs: Observable<any>): Observable<any> {
return of(1).pipe(
tap(() => this.spinner.startSpinner()),
mergeMap(() =>
obs.pipe(
NO_ERROR_OCCURED_RUN_HAPPY_PATH_CODE(() => this.generic_success_popup()),
catchError(this.handleError),
)
),
finalize(() => this.spinner.stopSpinner())
);
}
基本上,如果管道上没有错误抛出,几乎所有运算符都会被调用,除了 finalize
obs.pipe(
tap(_=>console.log('no error, will run'),
// throw some error
map(_=>throwError('some error'),
finalize(_=>console.log('will be called when there is error or upon observable complete')),
tap(_=>console.log('this will not run')),
catchError(this.handleError),
)
我正在尝试找到一种方法来 运行 只有在给定的 rxjs 链中没有错误的情况下才能编写一些代码。考虑以下问题,在 rxjs 中是否有类似人工 NO_ERROR_OCCURED_RUN_HAPPY_PATH_CODE
运算符的东西?
private wrap(obs: Observable<any>): Observable<any> {
return of(1).pipe(
tap(() => this.spinner.startSpinner()),
mergeMap(() =>
obs.pipe(
NO_ERROR_OCCURED_RUN_HAPPY_PATH_CODE(() => this.generic_success_popup()),
catchError(this.handleError),
)
),
finalize(() => this.spinner.stopSpinner())
);
}
基本上,如果管道上没有错误抛出,几乎所有运算符都会被调用,除了 finalize
obs.pipe(
tap(_=>console.log('no error, will run'),
// throw some error
map(_=>throwError('some error'),
finalize(_=>console.log('will be called when there is error or upon observable complete')),
tap(_=>console.log('this will not run')),
catchError(this.handleError),
)