mirror of
https://github.com/angular/angular.git
synced 2026-11-24 07:27:53 -05:00
docs: update deprecated exponential backoff example (#49494)
PR Close #49494
This commit is contained in:
committed by
Pawel Kozlowski
parent
97d58ec091
commit
cd5d7b6615
@@ -1,20 +1,17 @@
|
||||
// #docplaster
|
||||
// #docregion
|
||||
import { of, pipe, range, throwError, timer, zip } from 'rxjs';
|
||||
import { pipe, timer } from 'rxjs';
|
||||
import { ajax } from 'rxjs/ajax';
|
||||
import { map, mergeMap, retryWhen } from 'rxjs/operators';
|
||||
import { retry } from 'rxjs/operators';
|
||||
|
||||
export function backoff(maxTries: number, delay: number) {
|
||||
return pipe(
|
||||
retryWhen(attempts =>
|
||||
zip(range(1, maxTries + 1), attempts).pipe(
|
||||
mergeMap(([i, err]) => (i > maxTries) ? throwError(err) : of(i)),
|
||||
map(i => i * i),
|
||||
mergeMap(v => timer(v * delay)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
export function backoff(maxTries: number, initialDelay: number) {
|
||||
return pipe(
|
||||
retry({
|
||||
count: maxTries,
|
||||
delay: (error, retryCount) => timer(initialDelay * retryCount ** 2),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// #enddocregion
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user