title: RxJava retryWhen operator is not working as expected
body: <p>Suppose I have <code>List&lt;CharSequence&gt; observableList</code>, which contains random <code>CharSequence</code>'s which have length from 1 to 10.</p>
  
  <p>I have such <code>Observable</code>:</p>
  
  <pre><code>Observable.from(observableList)
          .flatMap(new Func1&lt;CharSequence, Observable&lt;CharSequence&gt;&gt;() {
              @Override
              public Observable&lt;CharSequence&gt; call(CharSequence charSequence) {
                  if (charSequence.length() == 1) {
                      return Observable.error(new RuntimeException("Too short"));
                  } else {
                      return Observable.just(charSequence);
                  }
              }
  }).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) {
          return observable.flatMap(new Func1&lt;Throwable, Observable&lt;?&gt;&gt;() {
              @Override
              public Observable&lt;?&gt; call(Throwable throwable) {
                  if (backoffStrategy.isApplicable(throwable)) {
                      Log.d(MainActivity.class.getSimpleName(), "Appropriate throwable is thrown!");
                      return backoffStrategy.call(observable);
                  }
                  return observable;
              }
          });
      }
  })
  </code></pre>
  
  <p>The observable throws exception, when the sequence length is 1. Inside <code>retryWhen</code>'s <code>Func1</code> I would like to check error type (<code>RuntimeException</code> is just an example) and choose appropriate retry strategy.</p>
  
  <p>This is the backoff strategy:</p>
  
  <pre><code>public class BaseBackoffStrategy implements BackoffStrategy {
  
      @Override
      public Observable&lt;?&gt; call(Observable&lt;? extends Throwable&gt; attempts) {
          return attempts.zipWith(Observable.range(1, 3 + 1), new ObservableUtils.RxPair&lt;Throwable, Integer&gt;())
                  .flatMap(new Func1&lt;Pair&lt;Throwable, Integer&gt;, Observable&lt;?&gt;&gt;() {
                      @Override
                      public Observable&lt;?&gt; call(Pair&lt;Throwable, Integer&gt; ti) {
                          if (ti.second &lt;= 3) {
                              System.out.println(new Date().toGMTString() + " : " + ti.second + " retry");
                              return Observable.timer((long) Math.pow(2, ti.second), TimeUnit.SECONDS);
                          } else {
                              return Observable.error(ti.first);
                          }
                      }
                  });
      }
  
      @Override
      public boolean isApplicable(Throwable throwable) {
          return RuntimeException.class.isInstance(throwable);
      }
  }
  
  private interface BackoffStrategy extends Func1&lt;Observable&lt;? extends Throwable&gt;, Observable&lt;?&gt;&gt; {
      boolean isApplicable(Throwable throwable);
  
  }
  </code></pre>
  
  <p>And the function just returning a <a href="https://stackoverflow.com/a/3646398/6507689"><code>Pair</code></a> of objects:</p>
  
  <pre><code>public class ObservableUtils {
  
      public static class RxPair&lt;T1, T2&gt; implements Func2&lt;T1, T2, Pair&lt;T1, T2&gt;&gt; {
          @Override
          public Pair&lt;T1, T2&gt; call(T1 t1, T2 t2) {
              return Pair.of(t1, t2);
          }
      }
  }
  </code></pre>
  
  <p>The ouput from the console is:</p>
  
  <pre><code>D/MainActivity: Appropriate throwable is thrown!
  I/System.out: 6 Oct 2016 07:34:34 GMT : 1 retry
  D/MainActivity: Appropriate throwable is thrown!
  I/System.out: 6 Oct 2016 07:34:36 GMT : 1 retry
  I/System.out: 6 Oct 2016 07:34:36 GMT : 2 retry
  D/MainActivity: Appropriate throwable is thrown!
  I/System.out: 6 Oct 2016 07:34:38 GMT : 1 retry
  I/System.out: 6 Oct 2016 07:34:38 GMT : 3 retry
  I/System.out: 6 Oct 2016 07:34:38 GMT : 2 retry
  D/MainActivity: Appropriate throwable is thrown!
  I/System.out: 6 Oct 2016 07:34:40 GMT : 1 retry
  I/System.out: 6 Oct 2016 07:34:40 GMT : 3 retry
  I/System.out: 6 Oct 2016 07:34:40 GMT : 2 retry
  D/MainActivity: Appropriate throwable is thrown!
  I/System.out: 6 Oct 2016 07:34:40 GMT : 1 retry
  I/System.out: 6 Oct 2016 07:34:40 GMT : 3 retry
  I/System.out: 6 Oct 2016 07:34:40 GMT : 2 retry
  D/MainActivity: onError
  </code></pre>
  
  <p>But I would like the <code>Observable</code> to retry after the specified time. The time should become longer, when the next exception is thrown. The output from console should look like:</p>
  
  <pre><code>D/MainActivity: Appropriate throwable is thrown!
  I/System.out: 6 Oct 2016 07:34:34 GMT : 1 retry
  D/MainActivity: Appropriate throwable is thrown!
  I/System.out: 6 Oct 2016 07:34:36 GMT : 2 retry
  D/MainActivity: Appropriate throwable is thrown!
  I/System.out: 6 Oct 2016 07:34:38 GMT : 3 retry
  D/MainActivity: Appropriate throwable is thrown!
  D/MainActivity: onError
  </code></pre>
  
  <blockquote>
    <p>My question is: what am I doing wrong here? Can I call other <code>Func1</code> from <code>Func1</code>?</p>
  </blockquote>