我使用了retryWhen与bufferWhen操作符在我的代码。但是不推荐使用retryWhen。我可以使用哪个操作符而不是retryWhen?这是我的代码:
of(1)
.pipe(
tap(() => {
if (this.webBusy) {
throw 2;
}
}),
retryWhen(errors =>
errors.pipe(
tap(val => console.log(`Nav ${val} WebBusy`)),
bufferWhen(() => this.doNextAct$)
)
),
switchMap((resp: SvcResponse) => {
this.webBusy = true;
return api.doAct(navData);
}),
tap((resp: SvcResponse) => {
this.webBusy = false;
this.doNextAct$.next(1);
}),
).subscribe()
我尝试使用延迟操作符,但我在将其与bufferWhen操作符组合时遇到麻烦。
正如RxJS的retryWhen中所描述的,你可以使用重试和延迟配置。
retry({
delay: (err, count) => {
console.log(`retried ${count} times`);
// if the retry count reach 2 then stop and throw an error
if (count == 2) {
throw new Error(err);
}
// otherwise keep retrying until the notifier completes with bufferWhen
return notifire.pipe(bufferWhen(() => this.doNextAct$));
},
})
查看我的stackblitz示例