title: Periodically call an observable and switch to next one only when next one succeeds
body: <p>I need to poll endpoint every second, currently I do it with </p>
  
  <pre><code>Observable.interval(0, 1, TimeUnit.SECONDS, ioScheduler)
      .switchMap { return pollWithRetrofit() }
  </code></pre>
  
  <p>It works fine except the situation when the calls start taking more than 1 second to process, so the retrofit subscription is cancelled by <code>swithMap</code> before I get any response. It can happen multiple times in a row, effectively leaving the client without any response from the poll calls for long duration. In this case I would like to not cancel the retrofit call until I get a response from the next call.</p>
  
  <p>I know that <code>switchMap</code> cancels the previous subscription when the base subscription produces <code>onNext</code> call, currently it happens every second by the <code>Observable.interval</code>, so my idea is to cancel previous call only when the retrofit calls it's <code>onNext</code>, i.e moving the switching one step forward the reactive chain.</p>
  
  <p>How do I do that? Or is there some other solution?</p>