I am trying to use retry with delay function, I expect function will call after 1000ms delay, but it doesnot, what can be error here?
look at conso
I came to this conclusion, in order to retry with other operations in the http pipe
import {delay as _delay, map, retryWhen} from 'rxjs/operators';
export const delayedRetry = (delay, retries = 1) => retryWhen(result => {
let _retries = 0;
return result.pipe(
_delay(delay),
map(error => {
if (_retries++ === retries) {
throw error;
}
return error;
}),
);
},
);
Usage
http.pipe(
delayedRetry(1500, 2),
catchError((err) => {
this.toasterService.error($localize`:@@not-saved:Could not save`);
return of(false);
}),
finalize(() => this.sending = false),
).subscribe((success: boolean) => {
if (success === true) {
this.toasterService.success($localize`:@@saved:Saved`);
}
}
});