title: retry / repeat with delay not working in RxJava2
body: <p>I am upgrading to rxjava2, we have the code to poll the data from server, the code handles to retry with delays when there is a network issue. However, somehow when i was trying to migrate to rxjava2, the code stops working. 
  Here is the code for Rxjava1, and <strong>its working perfectly</strong> , basically followed this <a href="http://blog.danlew.net/2015/03/02/dont-break-the-chain/" rel="nofollow noreferrer">http://blog.danlew.net/2015/03/02/dont-break-the-chain/</a> and this <a href="https://medium.com/@v.danylo/server-polling-and-retrying-failed-operations-with-retrofit-and-rxjava-8bcc7e641a5a" rel="nofollow noreferrer">https://medium.com/@v.danylo/server-polling-and-retrying-failed-operations-with-retrofit-and-rxjava-8bcc7e641a5a</a></p>
  
  <pre><code>.retryWhen(new Func1&lt;Observable&lt;? extends Throwable&gt;, Observable&lt;?&gt;&gt;() {
                  @Override
                  public Observable&lt;?&gt; call(final Observable&lt;? extends Throwable&gt; observable) {
                      // wrap a flatmap here so that i can check the exception type
                      return observable.flatMap(new Func1&lt;Throwable, Observable&lt;?&gt;&gt;() {
                          @Override
                          public Observable&lt;?&gt; call(Throwable throwable) {
                              mThrowable = throwable;
                              if (throwable instanceof IOException) {
                                  return observable.compose(timerWithRetries());
                              } else {
                                  // for other errors, call onError and exit
                                  return Observable.error(throwable);
                              }
                          }
                      });
                  }
              })
  
  
  
  private &lt;T&gt; Observable.Transformer&lt;T, Long&gt; timerWithRetries() {
      return new Observable.Transformer&lt;T, Long&gt;() {
  
          @Override
          public Observable&lt;Long&gt; call(Observable&lt;T&gt; observable) {
              return observable
                      .zipWith(Observable.range(COUNTER_START, MAX_RETRIES + 1),
                              new Func2&lt;T, Integer, Integer&gt;() {
                                  @Override
                                  public Integer call(T t, Integer repeatAttempt) {
                                      return repeatAttempt;
                                  }
                              })
                      .flatMap(new Func1&lt;Integer, Observable&lt;Long&gt;&gt;() {
                          @Override
                          public Observable&lt;Long&gt; call(Integer repeatAttempt) {
                              if (repeatAttempt == MAX_RETRIES + 1) {
                                  if (mThrowable instanceof IOException) {
                                    // Custom Exception
                                     throw new Exception();
                                  }
                              }
                              // increase the waiting time
                              return Observable.timer(repeatAttempt * mDelaySeconds, TimeUnit.SECONDS);
                          }
                      });
          }
      };
  }
  </code></pre>
  
  <p>I want to wrap the error with flatmap so that i can check the exception type and when it reaches to the maximum retries, i can pass my custom exception to onError. </p>
  
  <p>However, when just use Rxjava2, the timerWithRetries() method stops working, this method is called but the .zipWith() and its flatmap are not executed. </p>
  
  <p><strong>But its working without the flatmap when wrapping the error</strong>, which is very weird. Something like </p>
  
  <pre><code>.retryWhen(error -&gt; error.compose(timerWithRetries()))
  </code></pre>
  
  <p>Much appreciated with any suggestions!</p>