Skip to content

Commit 4874bbe

Browse files
committed
1.x: Single.retryWhen javadoc clarifications (#3909)
1 parent cac7430 commit 4874bbe

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/main/java/rx/Single.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,10 +2603,28 @@ public final Single<T> retry(Func2<Integer, Throwable, Boolean> predicate) {
26032603
* Returns a Single that emits the same values as the source Single with the exception of an
26042604
* {@code onError}. An {@code onError} notification from the source will result in the emission of a
26052605
* {@link Throwable} item to the Observable provided as an argument to the {@code notificationHandler}
2606-
* function. If that Observable calls {@code onComplete} or {@code onError} then {@code retry} will call
2607-
* {@code onCompleted} or {@code onError} on the child subscription. Otherwise, this Observable will
2608-
* resubscribe to the source Single.
2609-
*
2606+
* function.
2607+
* <p>Emissions from the handler {@code Observable} is treated as follows:
2608+
* <ul>
2609+
* <li>If the handler {@code Observable} emits an {@code onCompleted} the {@code retryWhen} will call {@code onError}
2610+
* with {@code NoSuchElementException} on the child subscription.</li>
2611+
* <li>If the handler {@code Observable} emits an {@code onError} the {@code retryWhen} will call
2612+
* {@code onError} with the same Throwable instance on the child subscription.
2613+
* <li>Otherwise, the operator will resubscribe to the source Single.</li>
2614+
* </ul>
2615+
* <p>The {@code notificationHandler} function is called for each subscriber individually. This allows per-Subscriber
2616+
* state to be added to the error notification sequence.</p>
2617+
* <pre><code>
2618+
* single.retryWhen(error -&gt; {
2619+
* AtomicInteger counter = new AtomicInteger();
2620+
* return error.takeWhile(e -&gt; counter.incrementAndGet() &lt; 3).map(e -&gt; "retry");
2621+
* }).subscribe(...);
2622+
* </code></pre>
2623+
* <p>
2624+
* Note that you must compose over the input {@code Observable} provided in the function call because {@retryWhen} expects
2625+
* an emission of the exception to be matched by an event from the handler Observable.
2626+
* <p>
2627+
*
26102628
* <img width="640" height="430" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/retryWhen.f.png" alt="">
26112629
*
26122630
* <dl>

0 commit comments

Comments
 (0)