I am looking for a way to monitor the progress of a certain task using API calls.
To achieve this, I have developed a service that executes these API calls every 1.5 seconds
Main Component
private getProgress() {
this.progressService.getExportProgress(this.type, this.details.RequestID);
}
Services.ts
public getExportProgress(type: string, requestId: string) {
Observable.interval(1500)
.switchMap(() => this.http.get(this.apiEndpoint + "Definition/" + type + "/Progress/" + requestId))
.map((data) => data.json().Data)
.subscribe(
(data) => {
if (!data.InProgress)
// Stop further API calls here
},
error => this.handleError(error));
}
Although the API call is functioning properly, it continues even after the progress is complete (if (!data.InProgress
). I need help in figuring out how to unsubscribe from the observable when this condition is met.
Any suggestions on how I can implement an unsubscribe feature based on if (!data.InProgress)
?
Appreciate any guidance