title: How to switch to another pipeline in rxjs?
body: <p>I have two subjects:</p>
  <pre><code>const foo = new Subject();
  const bar = new Subject();
  </code></pre>
  <p>And each of them acting different:</p>
  <pre><code>const foo$ = foo.pipe(
    tap(() =&gt; {
      console.log('in foo');
    })
  );
  
  const bar$ = bar.pipe(
    tap(() =&gt; {
      console.log('in bar');
    }),
  );
  </code></pre>
  <p>When I call <code>bar.next</code> to trigger the <code>bar$</code> pipeline and it's of course works as expected.</p>
  <p>But I want to trigger the <code>foo$</code> pipeline within the <code>bar$</code> pipeline like that:</p>
  <pre><code>const foo$ = foo.pipe(
    tap(() =&gt; {
      console.log('in foo');
    })
  );
  
  const bar$ = bar.pipe(
    tap(() =&gt; {
      console.log('in bar');
    }),
    switchMap(() =&gt; foo$)
  );
  </code></pre>
  <p>This not working.</p>
  <p>I have some limitations:</p>
  <ol>
  <li>I don't want to trigger the subject because it trigger every subscribers somewhere in the app.</li>
  <li>I can't use <code>foo$.next</code> because it's <code>next</code> don't exist in <code>foo$</code>.</li>
  <li>I want to use <code>foo$</code> in the same pipeline of <code>bar$</code> using the pipeline.</li>
  </ol>
  <p>I try to wrap it in <code>from</code>, <code>switchMap</code>, <code>map</code>, <code>switchMapTo</code> - those not working.</p>
  <p>Any idea?</p>
  <p><a href="https://stackblitz.com/edit/rxjs-eqcnsz?devtoolsheight=60" rel="nofollow noreferrer">stackblitz</a></p>
  <pre><code>import { Subject, tap } from 'rxjs';
  import { switchMap } from 'rxjs/operators';
  
  console.clear();
  
  const foo = new Subject();
  const bar = new Subject();
  
  const foo$ = foo.pipe(
    tap(() =&gt; {
      console.log('in foo');
    })
  );
  
  const bar$ = bar.pipe(
    tap(() =&gt; {
      console.log('in bar');
    }),
    switchMap(() =&gt; foo$)
  );
  
  bar$.subscribe();
  
  bar.next(1);
  </code></pre>