Skip to content

Commit

Permalink
docs(retry): add example for retry operator (#4691)
Browse files Browse the repository at this point in the history
  • Loading branch information
waseemahmad31 authored and niklas-wortmann committed May 9, 2019
1 parent f213e0a commit f885b99
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/internal/operators/retry.ts
Expand Up @@ -15,6 +15,36 @@ import { MonoTypeOperatorFunction, TeardownLogic } from '../types';
* during failed subscriptions. For example, if an Observable fails at first but emits [1, 2] then succeeds the second
* time and emits: [1, 2, 3, 4, 5] then the complete stream of emissions and notifications
* would be: [1, 2, 1, 2, 3, 4, 5, `complete`].
*
* ## Example
* ```ts
* import { interval, of, throwError } from 'rxjs';
* import { mergeMap, retry } from 'rxjs/operators';
*
* const source = interval(1000);
* const example = source.pipe(
* mergeMap(val => {
* if(val > 5){
* return throwError('Error!');
* }
* return of(val);
* }),
* //retry 2 times on error
* retry(2)
* );
*
* const subscribe = example.subscribe({
* next: val => console.log(val),
* error: val => console.log(`${val}: Retried 2 times then quit!`)
* });
*
* // Output:
* // 0..1..2..3..4..5..
* // 0..1..2..3..4..5..
* // 0..1..2..3..4..5..
* // "Error!: Retried 2 times then quit!"
* ```
*
* @param {number} count - Number of retry attempts before failing.
* @return {Observable} The source Observable modified with the retry logic.
* @method retry
Expand Down

0 comments on commit f885b99

Please sign in to comment.