Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

rxjs avoid nested subscription with combineLatest

I need to fix this nested subscriptions , but i have some difficulties 🙁
could you help me please to find a solution?

combineLatest([stream1,stream2])
    .pipe(takeUntil(this.destroyed$))
    .subscribe({
      next: ([a, b]) => {
        this.extService.get(a,b).subscribe();
      },
    });

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In this case you would have to use switch map after, this way it will "change" to the new subscription

combineLatest([stream1,stream2])
    .pipe(
          takeUntil(this.destroyed$),
          switchMap(([a,b])=>this.extService.get(a,b)
     )
)
    .subscribe(
   (responseFromExtService) => { // your code}
);

Make sure you know also the difference between combine lastest and fork join

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading