title: How do I use values emitted by 2 observables as parameters to an http request, with 1 observable resetting the other to a default value?
body: <p>I am subscribing to a mapped observable that is based on 2 other observables. Whenever either of the 2 emits a value, I want the mapped observable to emit.</p>
  <p>Whenever the outer observable emits, the inner observable value should reset to the default value (0 in the example). The problem is that when I reset the inner value, an extra value is emitted.</p>
  <p>(For context - the 2 observables provide parameters for an http request, which is the mapped observable. A new outer value should reset the inner value to 0)</p>
  <pre><code>const outer = new Subject();
  const inner = new BehaviorSubject(0);
  const http = of(&quot;&quot;);
  let mapped = outer.pipe(
    tap(() =&gt; inner.next(0)),
    switchMap(outerVal =&gt; {
      return inner.pipe(map(innerVal =&gt; ({ innerVal, outerVal })));
    }),
    switchMap(({ innerVal, outerVal }) =&gt; {
      return http.pipe(tap(() =&gt; console.log(&quot;http: &quot;, outerVal, innerVal)));
    })
  );
  
  mapped.subscribe(result =&gt; {
    console.log(result);
  });
  
  outer.next(&quot;first&quot;);
  inner.next(1);
  inner.next(2);
  outer.next(&quot;second&quot;);
  inner.next(3);
  
  
  // http: first 0
  // http: first 1
  // http: first 2
  // http: first 0 &lt;--- extra
  // http: second 0
  // http: second 3
  </code></pre>
  <p>I know why it's happening but I'm not sure how to deal with it. I have a solution that gets the correct results at the bottom of this stackblitz, but I think it's causing a memory leak.</p>
  <p><a href="https://stackblitz.com/edit/rxjs-mxc5wq?file=index.ts" rel="nofollow noreferrer">https://stackblitz.com/edit/rxjs-mxc5wq?file=index.ts</a></p>