title: RxJs Observable completes multiple times
body: <p>Below is a short code snippet of reactive code (<code>RxJs</code>)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let subj = new Rx.Subject();
  let chain = subj
      .switchMap(v =&gt; Rx.Observable.of(10*v).do(vv =&gt; console.log("Switch map", vv)))
      .share()
      .take(1);
  
  
  function subscribe(){
    chain.subscribe(v =&gt; console.log("Next", v),
                    err =&gt; console.log("Error",err),
                    () =&gt; console.log("Completed"));
    chain.subscribe(v =&gt; console.log("Next2", v),
                    err =&gt; console.log("Error2",err),
                    () =&gt; console.log("Completed2"));
    subj.next(Math.random());
  }
  
  subscribe();
  subscribe();
  subscribe();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://unpkg.com/rxjs/bundles/Rx.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>According to the <a href="http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html" rel="nofollow noreferrer">documentation</a> <code>chain</code> is an <code>Observable</code> which should print the emitted value * 10 (<a href="http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-switchMap" rel="nofollow noreferrer">switchMap</a>), while printing it only once, no matter what's the number of subscriptions it has (<a href="http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-share" rel="nofollow noreferrer">share</a>), do it only for the first emitted value and then complete.  </p>
  
  <p>The first two bullets work fine, but the last one does not. 
  Here is the output I get:  </p>
  
  <pre><code>Switch map 9.022491050934722
  Next 9.022491050934722
  Completed
  Next2 9.022491050934722
  Completed2
  Switch map 9.172999425126836
  Next 9.172999425126836
  Completed
  Next2 9.172999425126836
  Completed2
  Switch map 6.168790337405257
  Next 6.168790337405257
  Completed
  Next2 6.168790337405257
  Completed2
  </code></pre>
  
  <p>As you can see, <code>chain</code> is getting completed multiple times.<br>
  What makes it possible to complete the same <code>Observable</code> multiple times?</p>