Given two subjects s1
and s2
with subscriptions,
const s1 = new Subject<number>();
const s2 = new Subject<number>();
s1.subscribe({
next: (value) => console.log("s1 emitted", value),
complete: () => console.log("s1 completed"),
});
s2.subscribe({
next: (value) => console.log("s2 emitted", value),
complete: () => console.log("s2 completed"),
});
and given an observable, say of(1)
, I could pipe through s1
like so:
of(1).pipe(tap(s1)).subscribe();
which produces the output
s1 emitted 1
s1 completed
But what if you’d like to pipe through s1
AND s2
at once.
Of course I could do something like this:
of(1)
.pipe(tap((x) => [s1, s2].forEach((s) => of(x).subscribe(s))))
.subscribe();
which produces the output
s1 emitted 1
s1 completed
s2 emitted 1
s2 completed
But is there a better/shorter way? I tried merge
and the lot, but nothing works.