I used retryWhen with the bufferWhen operator in my code. But retryWhen is deprecated. Which operator can I use instead of retryWhen? This is my code:
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()
I tried using the delay operator but I'm having trouble combining it with the bufferWhen operator.
CodePudding user response:
As described in the RxJS retryWhen, you can use retry with the delay config instead.
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$));
},
})
Checkout my stackblitz example