I want to retry an observable chain with a delay (say, 2 seconds).
There are some similar questions answered with retryWhen. But retryWhen seems deprecated and I don't want to use it.
- The delay and retry is applicable only if the first try fails
- If all the retries failed, I want to respond with default data.
The following code works, without adding the delay, but how can I add delay into this chain?
of('trigger')
.pipe(
switchMap(() => fetchData()),
retry(5),
catchError(() => of(returnThisIfRetriesAreFailed))
)
.subscribe(console.log);
I tried adding delay(2000), but it does not seem to be working.