title: Better way to return conditional rxjs Observable
body: <p>In the following code, are the functions <code>onReady1()</code> and <code>onReady2()</code> equivalent? What are the differences? Is there a better way to write this function? </p>
  
  <p>The <code>onReadyx()</code> functions should return the user if it is available right away, or it would wait until its available. There will be multiple calls to this function at any given time.</p>
  
  <pre><code>export class UserService {
      private _user: IUser;
  
      private userObservable: Observable&lt;IUser&gt;;
  
      constructor(private http: Http) {
          this.userObservable = this.getCurrentUser();
      }
  
      public onReady1() {
          return Observable.create((observer: Observer&lt;IUser&gt;) =&gt; {
              if (this._user) {
                  observer.next(this._user);
                  observer.complete();
                  return;
              }
  
              this.userObservable.subscribe(user =&gt; {
                  this._user = user;
                  observer.next(user);
                  observer.complete();
              });
          });
      }
  
      public onReady2() {
          return Observable.defer(() =&gt; {
              if (this._user) {
                  return Observable.of(this._user);
              }
  
              return this.userObservable.do(user =&gt; this._user = user);
          });
      }
  
      private getCurrentUser() {
          return this.http.get('/currentuser')
              .map(response =&gt; response.json() as IUser);
      }
  
  }
  </code></pre>