title: shareReplayLatestWhileConnected with RxJS
body: <p>I'm creating my source observable like this (make api call every 5s):</p>
  
  <p><code>const obs$ = Observable.interval(5000).switchMap(() =&gt; makeApiCall());</code></p>
  
  <p>And I want to modify <code>$obs</code> so that it has the following characteristics:</p>
  
  <ul>
  <li>start the observable only when at there's at least 1 subscriber</li>
  <li>multicast. I.e. if I <code>obs$.subscribe(...)</code> twice, the underlying code <code>makeApiCall()</code> should only run once.</li>
  <li>any subscriber which subscribes at any time should have immediately the last emitted value (and not wait ~5s until the next value emits)</li>
  <li>retryable. If one <code>makeApiCall()</code> errors, I want (if possible) all subscribers to get an error notification, but reconnect to <code>$obs</code>, and continue doing <code>makeApiCall()</code> every 5s</li>
  </ul>
  
  <p>So far I found the following leads:</p>
  
  <p>It seems like I'd need to create a BehaviorSubject <code>myBehaviorSubject</code>, do a single subscription <code>obs$.subscribe(myBehaviorSubject)</code>, and any other observers should subscribe to <code>myBehaviorSubject</code>. Not sure if that answers the "retryable" part.</p>
  
  <p>I also looked at shareReplay, seems like <code>$obs.shareReplay(1)</code> would do the trick (for the 4 requirements). If I understood correctly it subscribes a ReplaySubject(1) to the source observable, and future observers subscribe to this ReplaySubject. Is there an equivalent shareBehavior?</p>
  
  <p>In RxSwift, I found shareReplayLatestWhileConnected, which seems like the shareBehavior I was imagining. But it doesn't exist in RxJS.</p>
  
  <p>Any ideas what is the best way to achieve this?</p>