I am new to RxJs. I need to poll a http request and continue polling until I get a positive response or a specified amount of time has elapsed (don't want to poll forever).
I am using Angular 8 and Typescript. Here is my code:
this.httpClient.get('http://localhost:8060/api/portal/v1/payment/fetch/' + shopId + '/0/10').pipe(
repeatWhen(obs => obs.pipe(delay(5000))),
filter((data: ResponseModel<any>) => {
console.log('Data:' + data);
return data.status === 'success';
}),
take(1)
).subscribe(result => {
console.log('Result: ' + result);
});
The code above works for positive response from server but if there is no positive response it polls forever which is not the desired effect. How do I add a timeout in the above functionality?