import { timer , interval , race , Observable } from 'rxjs' ; import { map , mergeMap , startWith } from 'rxjs/operators' ; export const pollWithTimeOut = ( pollingInterval , maxTimeout , poll ) : Observable < any > => { const timeOut = timer ( maxTimeout ) . pipe ( map ( ( ) => null ) ) ; const pollReceipt = interval ( pollingInterval ) . pipe ( startWith ( 0 ) , mergeMap ( ( ) => poll ) ) ; return race ( timeOut , pollReceipt ) ; } ;