import { Injectable } from '@nestjs/common' ; import { interval , Observable , of , throwError } from 'rxjs' ; import { RxjsService } from './rxjs/rxjs.service' ; import { catchError , mergeMap , retryWhen , skip , take } from 'rxjs/operators' ; @ Injectable ( ) export class AppService { constructor ( private readonly rxjsService ) { } playWithRxJS ( maxVal = 5 , takeAmount = 10 ) { return interval ( 100 ) . pipe ( skip ( 1 ) , take ( takeAmount ) , mergeMap ( ( val ) => { if ( val % maxVal === 0 ) { return throwError ( new Error ( `Val is equal to ${ maxVal }` ) ) ; } return of ( val ) ; } ) , retryWhen ( this . rxjsService . genericRetryStrategy ( ) ) , catchError ( ( err ) => { throw err ; } ) ) ; } }