I'd like to implement a retry mechanism for an observable chain with a delay of 2 seconds.
While researching, I found some solutions using retryWhen
. However, it appears that retryWhen
is deprecated and I prefer not to use it.
- The retry with delay should only be triggered if the initial attempt fails
- If all retries fail, I wish to handle it by providing default data
The code below works fine without the delay, but how can I incorporate a delay into this chain?
of('trigger')
.pipe(
switchMap(() => fetchData()),
retry(5),
catchError(() => of(returnThisIfRetriesAreFailed))
)
.subscribe(console.log);
I attempted to add delay(2000)
, but it doesn't seem to be effective.