0
votes

a$.pipe(withLatestFrom(b$)) emits value only if b$ is cold observable (or Behavior/ReplaySubject).
But what if both a$ and b$ are hot observables ?
I this case resulting observable will never emit

I think the solution would be to do

b2$ = b$.pipe(publishReplay(1))
b2$.connect()

and then

a$.pipe(withLatestFrom(b2$))

but it doesn't look right to me. What would be proper solution to this problem?

1

1 Answers

1
votes

a$.pipe(withLatestFrom(b$)) will emit when b$ emits first and a$ emits second.

If you want the resulting observable to emit as soon as a$ emits while b$ hasn't emitted yet you can use startWith to add an initial value to b$.

a$.pipe(
  withLatestFrom(b$.pipe(startWith(null)))
)