title: how to unsubscribe a RXJS subscription inside the subscribe method?
body: <p>I have some javascript:</p>
  <pre><code>this.mySubscription = someObservable.subscribe((obs: any) =&gt; {
     this.mySubscription.unsubscribe();
     this.mySubscription = undefined;
  }
  </code></pre>
  <p>on execution, the console logs the error <code>ERROR TypeError: Cannot read property 'unsubscribe' of undefined</code>.
  I wonder why I can not unsubscribe inside the subscribe lambda function. Is there a correct way to do so? I have read a bit about using dummy-subjects and completing them or using takeUntil/takeWhile and other pipe operators workArounds.</p>
  <p>What is a correct way/workaround to unsubscribe a subscription inside the subscription's subscribe-function?</p>
  <p>I am currently using a dummy subscription like so:</p>
  <pre><code>mySubscription: BehaviorSubject&lt;any&gt; = new BehaviorSubject&lt;any&gt;(undefined);
  
  
  // when I do the subscription:
  dummySubscription: BehaviorSubject&lt;any&gt; = new BehaviourSubject&lt;any&gt;(this.mySubscription.getValue());
  this.mySubscription = someObservable.subscribe((obs: any) =&gt; {
      // any work...
      dummySubscription.next(obs);
      dummySubscription.complete();
      dummySubscription = undefined;
  }, error =&gt; {
      dummySubscription.error(error);
  });
  
  dummySubscription.subscribe((obs: any) =&gt; {
      // here the actual work to do when mySubscription  emits a value, before it should have been unsubscribed upon
  }, err =&gt; {
      // if errors need be
  });
  </code></pre>