User3250
User3250

Reputation: 3423

Do a process after FlatMap complete all requests

I am using RxJs 6.1.0 in Angular 6 to get data from multiple observables as below:

ngOnInit(){
 this.subscribeInit = this.tradingService.getInProgress()
  .do((s) => {
    this.keys = s.map((tdi)=> tdi.key);
    return this.keys;
  })
  .flatMap((key)=>this.tradingService.getTradingData(key))
  .subscribe((res)=>{        
    this.formattedData.push(res);
  });
}

I want to do a process after all observables have completed execution from flatMap i.e all data is pushed to formattedData.

Please guide me know how can I achieve this. Thank you.

Upvotes: 0

Views: 56

Answers (1)

martin
martin

Reputation: 96889

You just add the complete handler to subscribe():

...
.subscribe(
  res => ...,
  undefined,
  () => /* completed */
)

You you can use so-called "partial observer" object:

...
.subscribe({
  next: res => ...,
  complete: () => /* completed */,
})

Upvotes: 2

Related Questions