import { Observable , of , range , throwError , timer , zip } from 'rxjs' ; import { catchError , delayWhen , finalize , map , mergeMap , onErrorResumeNext , retry , retryWhen , tap } from 'rxjs/operators' ; let retryCount = 0 ; const obs$ = new Observable < number > ( observer => { if ( ++ retryCount == 3 ) { observer . next ( 42 ) ; observer . complete ( ) ; } else { console . log ( 'failed call' ) ; observer . error ( new Error ( 'woops' ) ) ; } } ) ; const num$ = obs$ . pipe ( retryWhen ( errors => { return zip ( errors , range ( 1 , 3 ) ) . pipe ( map ( ( [ _ , index ] ) => index ) , tap ( item => console . log ( `Retrying after ${ item } seconds` ) ) , delayWhen ( item => timer ( item * 1000 ) ) ) ; } ) ) ; num$ . subscribe ( { next : item => console . log ( `Next: ${ item }` ) , error : err => console . log ( `Error: ${ err . message }` ) } ) ;