private initiateAnalysis() {
this.initiateRequest$().pipe( // sends the first request to start the analysis
switchMap(() => interval(1000)), // when the response comes back, start emitting an event every second from this observable
mergeMap(() => this.checkForResponse$()), // each second, send the GET request and emit the results. Merge all the results into the resulting observable
filter(results => this.isAnalysisComplete(results)), // filter out the results if they are not the final, correct results
first() // only take the first complete results, to avoid continuing sending GET requests
).subscribe(results => this.showResults(results));
}
private initiateRequest$(): Observable<void> {
const params = {
};
return this.problemsService.postRequest('postURL', {}, params)
}
private checkForResponse$(): Observable<Results>{
const params = {
};
return this.problemsService.getResults('someURL', params);
}
private showResults(results: Results) {
console.log('results', results);
}Except this has one problem. The above code stops processing with the first result from the get.Not my use case. I need to get a response from the http get call, check the result for some condition, only if the condition
is met, I stop and show the results.
How can I pull that off?
--
You received this message because you are subscribed to a topic in the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/jeBO6DeC2VA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.