在不等待内部可观察结果的情况下发出可观察结果图

bf1o4zei  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(314)

目前我有以下类型的代码:

obsC$: Observable<Result[T][]> = combineLatest([this.obsA$, this.obsB$]).
 pipe(map(([resultA, resultB]) => ...),
 switchMap(this.serviceA.fetch(resultA).pipe(map((resultD) => ...)))
 )

这导致obsc$必须等待this.servicea.fetch的结果,我不想这样做,因为这可能需要一些时间。相反,我希望在switchmap之前发出一次结果,然后在switchmap完成后再次发出。有没有办法用上述方法做到这一点?或者我必须将其重构为单独的可观察对象吗?

xwbd5t1u

xwbd5t1u1#

你可以重写你的 switchMap()merge() 第一个结果,因此它会在 this.serviceA.fetch 发射。

switchMap(resultA => merge(
  of(resultA),
  this.serviceA.fetch(resultA).pipe(map((resultD) => ...))
))

相关问题