I'm trying to create a service that polls a log at given interval (every 5 seconds). I need to make an http GET call, but on slow connections and large logs, the switchMap
cancels the previous pending request. Thus, I'm never getting the log as the request is being canceled.
getLog(url:string):Observable<string> {
return Observable
.timer(0, 5000)
.switchMap(() => this.get(url))
.retryWhen(error => error.delay(5000))
.map((res:Response) => res.text())
.catch(e => {
console.warn(e.toString());
return Observable.from("");
});
}
and this.get(url)
is simply get(url) {return this.http.get(url)}
.
I am seeking to keep the timer functionality, but to not trigger another http call until the previous call has resolved, and to not cancel the pending call.