Home > Blockchain >  Synchronous handling of many streams in RxJS
Synchronous handling of many streams in RxJS

Time:07-22

Let's say that we have two Observable objects (observable A and observable B), both emitting at random. We do not know how often or in what fashion those Observables emit. Let's say that when Observable A emits a value, I want to wait until Observable B emits a value and then return it in a result Observable C. Basically each time Observable A emits, I want it to wait for Observable B to emit and then emit the values emitted in Observable C. All other values emitted in B stream I want to ignore. What operators can I use to achieve that?

CodePudding user response:

Maybe skipUntil filter and withLatestFrom operator can help you. skipUntil to ignore values emitted in B until A emits.

something like this:

    var test$ = B$.pipe(skipUntil(A$))
    var C$ = test$.pipe(
      withLatestFrom(A$), 
      map(([a,b]) => {
        return a
      }))
  • Related