[英]RxJS how to fire two http requests in parallel but wait for first to complete before second value is emitted
[英]how to make second stream work before first rxjs
this.productService.createProduct(form).subscribe((res) => {
this.fileUploadService.remove(imageName).subscribe((res) => {
this.closeDialog(true);
})
})
我從我的代碼中截取了這個,你怎么看,我在第一個請求中訂閱了第二個請求,我認為這是一個糟糕的解決方案,你知道如何使用 rxjs 運算符讓第二個 stream 在第一個之前工作嗎?
如果this.fileUploadService.remove
必須在this.productService.createProduct
之前執行,那么您可以嘗試
this.fileUploadService.remove(imageName).pipe(
concatMap(() => this.productService.createProduct(form))
).subscribe(() => {
this.closeDialog(true);
})
這里的關鍵是concatMap
的使用,它基本上是說“在上游通知一些值后執行下游”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.