docs: update deprecated exponential backoff example (#49494)

PR Close #49494
This commit is contained in:
Thomas Pischke
2023-03-21 07:58:06 +01:00
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
/*