Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Created October 30, 2022 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/2b8f620a84bd5d7a15825d0bd608923c to your computer and use it in GitHub Desktop.
Save NetanelBasal/2b8f620a84bd5d7a15825d0bd608923c to your computer and use it in GitHub Desktop.
import { repeat } from 'rxjs';
@Injectable({ providedIn: 'root' })
export class MetricsService {
private http = inject(HttpClient);
getMetrics() {
return this.http.get('https://metrics')
.pipe(
repeat({ delay: 30_000 }),
// 👇
retry(3),
// 👇
retry({
count: 3,
delay: 1000
}),
// 👇
retry({
count: 3,
delay: (error, count) => {
// Retry forever, but with an exponential step-back
// maxing out at 1 minute.
return timer(Math.min(60000, 2 ^ count * 1000))
},
})
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment