title: RxJava - retry: reset retry counter on successful resume
body: <p>Currently I'm using Observable.retry(n) in order to retry in case of error. Please take a look at this code:</p>
  
  <pre><code>@Test
  public void testObservableRetry() {
      Observable
              .&lt;String&gt;defer(() -&gt; Observable
                      .just(Notification.createOnNext("valid value"), Notification.createOnError(new Error("Test")))
                      .dematerialize())
              .doOnNext(v -&gt; System.out.println("onNext: " + v))
              .doOnError(e -&gt; System.out.println("onError: " + e.getMessage()))
              .doOnSubscribe(d -&gt; System.out.println("onSubscribe"))
              .doOnDispose(() -&gt; System.out.println("onDispose"))
              .retry(2)
              .take(2) // .take(4) will fail the test
              .blockingLast();
  }
  </code></pre>
  
  <p>The code above is able to resume after error, but the retry number is limited for total errors number and not consecutive errors. </p>
  
  <p>E.g. if you replace <code>.take(2)</code> with <code>.take(4)</code> - the test will fail, because total errors number will exceed 4, despite the fact that after each error it resumes and is able to get next value:</p>
  
  <pre><code>---(v1)----(error)---(v2)----(error)----(v3)-----(error)---(v4)-
  </code></pre>
  
  <p>I'd like to find a way to reset a counter after successful resume. The use case is for example network connection - I'd like to give the same number of tries on each disconnection, but after each successful connect I'd like to reset the counter in order to allow endless flow unless each time it's able to resume within constant number of tries.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Successful resume in this context means receiving at least 1 item after retry. So I'd like to limit only the number of consecutive errors, and not total errors.</p>