
The existing example makes it seem like zip is a pipeable operator. It can be used this way, but I think that is for backwards compatibility. You can achieve the same functionality by using it as an Observable creator. I think this also makes the example clearer. PR Close #26790
24 lines
472 B
TypeScript
24 lines
472 B
TypeScript
|
|
import { pipe, range, timer, zip } from 'rxjs';
|
|
import { ajax } from 'rxjs/ajax';
|
|
import { retryWhen, map, mergeMap } from 'rxjs/operators';
|
|
|
|
function backoff(maxTries, ms) {
|
|
return pipe(
|
|
retryWhen(attempts => zip(range(1, maxTries), attempts)
|
|
.pipe(
|
|
map(([i]) => i * i),
|
|
mergeMap(i => timer(i * ms))
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
ajax('/api/endpoint')
|
|
.pipe(backoff(3, 250))
|
|
.subscribe(data => handleData(data));
|
|
|
|
function handleData(data) {
|
|
// ...
|
|
}
|