I try to ping a URL/API continuous with rxjs.
My first try was:
timer(3000, 2000)
.pipe(mergeMap(() => this._http.get(environment.pingUrl)))
.subscribe(res => console.log(res), err => console.log(err))
But when the URL is not reachable i never get a response. So I decide to set a timeout:
timer(3000, 2000)
.pipe(mergeMap(() => this._http.get(environment.pingUrl).pipe(timeout(5000)))
.subscribe(res => console.log(res), err => console.log(err))
Now I get the first timeout/response when the api is not reachable, but then it seems the timeout trigger an unsubscribe for the timer and there is no further response. I have no idea to prevent this unsubscribe.