title: RxJava: database and remote server
body: <p>I have a list of objects that I want retrieve from a local database (if available), or from a remote server otherwise. I'm using RxJava Observables (SqlBrite for the database and Retrofit for the remote server).</p>
  
  <p>My query code is as follows:</p>
  
  <pre><code>Observable&lt;List&lt;MyObject&gt;&gt; dbObservable = mDatabase
              .createQuery(MyObject.TABLE_NAME,MyObject.SELECT_TYPE_A)
              .mapToList(MyObject.LOCAL_MAPPER);
  Observable&lt;List&lt;MyObject&gt;&gt; remoteObservable = mRetrofitService.getMyObjectApiService().getMyObjects();
  
  return Observable.concat(dbObservable, remoteObservable)
      .first(new Func1&lt;List&lt;MyObject&gt;, Boolean&gt;() {
                  @Override
                  public Boolean call(List&lt;MyObject&gt; myObjects) {
                      return !myObjects.isEmpty();
                  }
              });
  </code></pre>
  
  <p>I see the first observable running and hitting the first method with an empty list, but then the retrofit observable does not run, there is no network request. If I switch the order of the observables, or just return the remote observable, it works as expected, it hits the remote server and returns the list of objects.</p>
  
  <p>Why would the remote observable fail to run in this scenario? The subscriber's onNext, orError and onComplete methods are not called when I concatenate the observables with the db first and retrofit second.</p>
  
  <p>Thanks!</p>