UNPKG

1.9 kBTypeScriptView Raw
1import { Observable } from '../Observable';
2import { MonoTypeOperatorFunction } from '../types';
3/**
4 * Returns an Observable that mirrors the source Observable with the exception of an `error`. If the source Observable
5 * calls `error`, this method will emit the Throwable that caused the error to the Observable returned from `notifier`.
6 * If that Observable calls `complete` or `error` then this method will call `complete` or `error` on the child
7 * subscription. Otherwise this method will resubscribe to the source Observable.
8 *
9 * ![](retryWhen.png)
10 *
11 * Retry an observable sequence on error based on custom criteria.
12 *
13 * ## Example
14 * ```ts
15 * import { timer, interval } from 'rxjs';
16 * import { map, tap, retryWhen, delayWhen } from 'rxjs/operators';
17 *
18 * const source = interval(1000);
19 * const example = source.pipe(
20 * map(val => {
21 * if (val > 5) {
22 * // error will be picked up by retryWhen
23 * throw val;
24 * }
25 * return val;
26 * }),
27 * retryWhen(errors =>
28 * errors.pipe(
29 * // log error message
30 * tap(val => console.log(`Value ${val} was too high!`)),
31 * // restart in 5 seconds
32 * delayWhen(val => timer(val * 1000))
33 * )
34 * )
35 * );
36 *
37 * const subscribe = example.subscribe(val => console.log(val));
38 *
39 * // results:
40 * // 0
41 * // 1
42 * // 2
43 * // 3
44 * // 4
45 * // 5
46 * // "Value 6 was too high!"
47 * // --Wait 5 seconds then repeat
48 * ```
49 *
50 * @param {function(errors: Observable): Observable} notifier - Receives an Observable of notifications with which a
51 * user can `complete` or `error`, aborting the retry.
52 * @return A function that returns an Observable that mirrors the source
53 * Observable with the exception of an `error`.
54 */
55export declare function retryWhen<T>(notifier: (errors: Observable<any>) => Observable<any>): MonoTypeOperatorFunction<T>;
56//# sourceMappingURL=retryWhen.d.ts.map
\No newline at end of file