I would like to achieve the following:
Make a service call only 30 times OR until a specific condition is met.
The service must be called every 5 seconds.
It would be great if I could see only one console.log in the subscribe function.
Let's say the condition for stopping the service calls is when accuracy drops below 50. I started with the provided code but ran into call stack issues. Can anyone provide working code for this scenario? I am asking for help here while continuing my own search for a solution. If I manage to find it on my own, I will come back and share the answer. I may not have much experience in this area, but I am determined to learn as much as I can.
public randomExample() {
this.randomNumber().pipe(
map((n) => {
console.log('map', n);
if (n.accuracy > 50) {
throw n;
}
return n;
}),
retryWhen(e =>
e.pipe(
tap(n => console.log('value to high', n))
)),
delayWhen(n => timer(5000))
).subscribe((n) => {
console.log('subscribed', n);
})
}
public randomNumber(): Observable<{accuracy:number}> {
const n = Math.floor(Math.random() * 100)
let value = {accuracy:n}
return of(value);
}