Skip to content

Commit ebf6393

Browse files
mpodlasinbenlesh
authored andcommitted
docs(onErrorResumeNext): create documentation for the operator (#2571)
Create documentation for 'onErrorResumeNext' operator. Describe what it accepts and returns. Compare it to 'concat' operator. Add note about 'catch' operator. Provide example of usage.
1 parent 695f280 commit ebf6393

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/operator/onErrorResumeNext.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,69 @@ export function onErrorResumeNext<T, T2, T3, T4, T5, T6, R>(this: Observable<T>,
1616
export function onErrorResumeNext<T, R>(this: Observable<T>, ...observables: Array<ObservableInput<any> | ((...values: Array<any>) => R)>): Observable<R>;
1717
export function onErrorResumeNext<T, R>(this: Observable<T>, array: ObservableInput<any>[]): Observable<R>;
1818
/* tslint:enable:max-line-length */
19+
20+
/**
21+
* When any of the provided Observable emits an complete or error notification, it immediately subscribes to the next one
22+
* that was passed.
23+
*
24+
* <span class="informal">Execute series of Observables no matter what, even if it means swallowing errors.</span>
25+
*
26+
* <img src="./img/onErrorResumeNext.png" width="100%">
27+
*
28+
* `onErrorResumeNext` is an operator that accepts a series of Observables, provided either directly as
29+
* arguments or as an array. If no single Observable is provided, returned Observable will simply behave the same
30+
* as the source.
31+
*
32+
* `onErrorResumeNext` returns an Observable that starts by subscribing and re-emitting values from the source Observable.
33+
* When its stream of values ends - no matter if Observable completed or emitted an error - `onErrorResumeNext`
34+
* will subscribe to the first Observable that was passed as an argument to the method. It will start re-emitting
35+
* its values as well and - again - when that stream ends, `onErrorResumeNext` will proceed to subscribing yet another
36+
* Observable in provided series, no matter if previous Observable completed or ended with an error. This will
37+
* be happening until there is no more Observables left in the series, at which point returned Observable will
38+
* complete - even if the last subscribed stream ended with an error.
39+
*
40+
* `onErrorResumeNext` can be therefore though of as version of {@link concat} operator, which is more permissive
41+
* when it comes to the errors emitted by its input Observables. While `concat` subscribes to the next Observable
42+
* in series only if previous one successfully completed, `onErrorResumeNext` subscribes even if it ended with
43+
* an error.
44+
*
45+
* Note that you do not get any access to errors emitted by the Observables. In particular do not
46+
* expect these errors to appear in error callback passed to {@link subscribe}. If you want to take
47+
* specific actions based on what error was emitted by an Observable, you should try out {@link catch} instead.
48+
*
49+
*
50+
* @example <caption>Subscribe to the next Observable after map fails</caption>
51+
* Rx.Observable.of(1, 2, 3, 0)
52+
* .map(x => {
53+
* if (x === 0) { throw Error(); }
54+
return 10 / x;
55+
* })
56+
* .onErrorResumeNext(Rx.Observable.of(1, 2, 3))
57+
* .subscribe(
58+
* val => console.log(val),
59+
* err => console.log(err), // Will never be called.
60+
* () => console.log('that\'s it!')
61+
* );
62+
*
63+
* // Logs:
64+
* // 10
65+
* // 5
66+
* // 3.3333333333333335
67+
* // 1
68+
* // 2
69+
* // 3
70+
* // "that's it!"
71+
*
72+
* @see {@link concat}
73+
* @see {@link catch}
74+
*
75+
* @param {...ObservableInput} observables Observables passed either directly or as an array.
76+
* @return {Observable} An Observable that emits values from source Observable, but - if it errors - subscribes
77+
* to the next passed Observable and so on, until it completes or runs out of Observables.
78+
* @method onErrorResumeNext
79+
* @owner Observable
80+
*/
81+
1982
export function onErrorResumeNext<T, R>(this: Observable<T>, ...nextSources: Array<ObservableInput<any> |
2083
Array<ObservableInput<any>> |
2184
((...values: Array<any>) => R)>): Observable<R> {

0 commit comments

Comments
 (0)