title: rxjava: Can I use retry() but with delay?
body: <p>I am using rxjava in my Android app to handle network requests asynchronously. Now I would like to retry a failed network request only after a certain time has passed.</p>
  
  <p>Is there any way to use retry() on an Observable but to retry only after a certain delay?</p>
  
  <p>Is there a way to let the Observable know that is is currently being retried (as opposed to tried for the first time)?</p>
  
  <p>I had a look at debounce()/throttleWithTimeout() but they seem to be doing something different.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I think I found one way to do it, but I'd be interested in either confirmation that this is the correct way to do it or for other, better ways.</p>
  
  <p>What I am doing is this: In the call() method of my Observable.OnSubscribe, before I call the Subscribers onError() method, I simply let the Thread sleep for the desired amount of time. So, to retry every 1000 milliseconds, I do something like this:</p>
  
  <pre><code>@Override
  public void call(Subscriber&lt;? super List&lt;ProductNode&gt;&gt; subscriber) {
      try {
          Log.d(TAG, "trying to load all products with pid: " + pid);
          subscriber.onNext(productClient.getProductNodesForParentId(pid));
          subscriber.onCompleted();
      } catch (Exception e) {
          try {
              Thread.sleep(1000);
          } catch (InterruptedException e1) {
              e.printStackTrace();
          }
          subscriber.onError(e);
      }
  }
  </code></pre>
  
  <p>Since this method is running on an IO thread anyway it does not block the UI. The only problem I can see is that even the first error is reported with delay so the delay is there even if there's no retry(). I'd like it better if the delay wasn't applied <em>after</em> an error but instead <em>before</em> a retry (but not before the first try, obviously).</p>