Skip to content

Commit

Permalink
Use retryWhen() to Delay Retries
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kenny Nguyen authored and Kenny Nguyen committed May 31, 2024
1 parent 153e3eb commit 79b4d83
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/app/admin/services/donut.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';

import { catchError, map, of, tap, throwError, retry } from 'rxjs';
import { catchError, map, of, tap, throwError, retryWhen, delay, take } from 'rxjs';

import { Donut } from '../models/donut.model';

Expand All @@ -23,7 +23,7 @@ export class DonutService {
tap((donuts) => {
this.donuts = donuts;
}),
retry(2),
retryWhen((errors) => errors.pipe(delay(5000), take(2))),
catchError(this.handleError)
);
}
Expand Down

0 comments on commit 79b4d83

Please sign in to comment.