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

how to make second stream work before first rxjs

this.productService.createProduct(form).subscribe((res) => {
  this.fileUploadService.remove(imageName).subscribe((res) => {
    this.closeDialog(true);
  })
})

I have this snipped from my code and how you can see, I’m subscribing to second request inside first one, I think this is a bad solution, do you know how to make the second stream work before first one, by using rxjs operators?

>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

If the this.fileUploadService.remove has to be executed before this.productService.createProduct then you can try

this.fileUploadService.remove(imageName).pipe(
  concatMap(() => this.productService.createProduct(form))
).subscribe(() => {
    this.closeDialog(true);
})

The key here is the use of concatMap which basically says "execute downstream after the upstream has notified some values".

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