Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use retryWhen() to Delay Retries #3

Open
hazartilirot opened this issue Jun 10, 2023 · 0 comments
Open

Use retryWhen() to Delay Retries #3

hazartilirot opened this issue Jun 10, 2023 · 0 comments

Comments

@hazartilirot
Copy link

Actually, retryWhen is deprecated.
https://rxjs.dev/api/operators/retryWhen

read(): Observable<Donut[]> {
    return this.donuts.length ?
      of(this.donuts) :
      this.httpClient
          .get<Donut[]>(`/api/donuts`)
          .pipe(
            tap(donuts => this.donuts = donuts),
            retry({count: 10, delay: 5000}), // use this operator instead
            catchError(this.handleError)
          );
  }
CWKennyn pushed a commit to CWKennyn/angular-basics-seed that referenced this issue May 31, 2024
Learnt how to successfully retry a failed HTTP error. Merged things over to retryWhen (even though its been deprecated), learned about errors which is given to us as an observable, then pipe which allows us to pass in any operators that we like. Dealing with pure functions (delay and take) which then pass the values to the next. When our delay fires, our take is going to kick off, it's going to take the first value, then the second value which is then going to finish that observable. But if we come back online beforehand. It's not going to take it twice because we are not going to have a retry if it was successful the first time.

Alternative to retryWhen from someone also doing the same course:
ultimatecourses#3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant