How do I get RxViz to display several streams at once?

If you have been reading these blog entries, you have seen some of the things RxViz can do — but perhaps, you have tried to display an array of Observables and been frustrated by this error:

  Last expression must be an Observable

Well, darn. An Observable.  One.  I want to put a bunch on the screen, lined up top to bottom.

Consider, though, higher-order Observables; that is, Observables that emit other Observables.  Like this ship that carries other ships:

Image result for ship carrying ships

RxViz does a beautiful job of displaying higher-order Observables.  See here for good example.

And you might hope that therefore you could display several Observables just by packing them up in a single containing Observable, like this:

of(p0, p1, p2)

It almost works.  All three Observables are displayed, just not in any predictable order.  Sometimes,  p2 is at the bottom; sometimes at the top.  Why RxViz  has this problem I don’t know, but you can defeat it by emitting the Observables not all at once, but one after another, a millisecond apart, like this:

  function vizDisplay(...observables) {
    return timer(0, 1).pipe(
      take(observables.length),
      map(n => observables[n]),
    );
  }


The code is here.

Next: “How do I compose Observables analogously to Promise.all?”

Comments

Popular posts from this blog

How do I create a timeout?

How can I tell if an Observable is running or not?