Skip to content

2.x: Improve JavaDoc of retryWhen() operators #5773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/io/reactivex/Completable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,31 @@ public final Completable retry(Predicate<? super Throwable> predicate) {
* Returns a Completable which given a Publisher and when this Completable emits an error, delivers
* that error through a Flowable and the Publisher should signal a value indicating a retry in response
* or a terminal event indicating a termination.
* <p>
* Note that the inner {@code Publisher} returned by the handler function should signal
* either {@code onNext}, {@code onError} or {@code onComplete} in response to the received
* {@code Throwable} to indicate the operator should retry or terminate. If the upstream to
* the operator is asynchronous, signalling onNext followed by onComplete immediately may
* result in the sequence to be completed immediately. Similarly, if this inner
* {@code Publisher} signals {@code onError} or {@code onComplete} while the upstream is
* active, the sequence is terminated with the same signal immediately.
* <p>
* The following example demonstrates how to retry an asynchronous source with a delay:
* <pre><code>
* Completable.timer(1, TimeUnit.SECONDS)
* .doOnSubscribe(s -&gt; System.out.println("subscribing"))
* .doOnComplete(() -&gt; { throw new RuntimeException(); })
* .retryWhen(errors -&gt; {
* AtomicInteger counter = new AtomicInteger();
* return errors
* .takeWhile(e -&gt; counter.getAndIncrement() == 3)
* .flatMap(e -&gt; {
* System.out.println("delay retry by " + counter.get() + " second(s)");
* return Flowable.timer(counter.get(), TimeUnit.SECONDS);
* });
* })
* .blockingSubscribe(System.out::println, System.out::println);
* </code></pre>
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code retryWhen} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/io/reactivex/Flowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -11770,19 +11770,19 @@ public final Flowable<T> retryUntil(final BooleanSupplier stop) {
* resubscribe to the source Publisher.
* <p>
* <img width="640" height="430" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/retryWhen.f.png" alt="">
*
* <p>
* Example:
*
* This retries 3 times, each time incrementing the number of seconds it waits.
*
* <pre><code>
* Publisher.create((Subscriber&lt;? super String&gt; s) -&gt; {
* Flowable.create((FlowableEmitter&lt;? super String&gt; s) -&gt; {
* System.out.println("subscribing");
* s.onError(new RuntimeException("always fails"));
* }).retryWhen(attempts -&gt; {
* }, BackpressureStrategy.BUFFER).retryWhen(attempts -&gt; {
* return attempts.zipWith(Flowable.range(1, 3), (n, i) -&gt; i).flatMap(i -&gt; {
* System.out.println("delay retry by " + i + " second(s)");
* return Publisher.timer(i, TimeUnit.SECONDS);
* return Flowable.timer(i, TimeUnit.SECONDS);
* });
* }).blockingForEach(System.out::println);
* </code></pre>
Expand All @@ -11798,9 +11798,35 @@ public final Flowable<T> retryUntil(final BooleanSupplier stop) {
* delay retry by 3 second(s)
* subscribing
* } </pre>
* <p>
* Note that the inner {@code Publisher} returned by the handler function should signal
* either {@code onNext}, {@code onError} or {@code onComplete} in response to the received
* {@code Throwable} to indicate the operator should retry or terminate. If the upstream to
* the operator is asynchronous, signalling onNext followed by onComplete immediately may
* result in the sequence to be completed immediately. Similarly, if this inner
* {@code Publisher} signals {@code onError} or {@code onComplete} while the upstream is
* active, the sequence is terminated with the same signal immediately.
* <p>
* The following example demonstrates how to retry an asynchronous source with a delay:
* <pre><code>
* Flowable.timer(1, TimeUnit.SECONDS)
* .doOnSubscribe(s -&gt; System.out.println("subscribing"))
* .map(v -&gt; { throw new RuntimeException(); })
* .retryWhen(errors -&gt; {
* AtomicInteger counter = new AtomicInteger();
* return errors
* .takeWhile(e -&gt; counter.getAndIncrement() == 3)
* .flatMap(e -&gt; {
* System.out.println("delay retry by " + counter.get() + " second(s)");
* return Flowable.timer(counter.get(), TimeUnit.SECONDS);
* });
* })
* .blockingSubscribe(System.out::println, System.out::println);
* </code></pre>
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator honors downstream backpressure and expects the source {@code Publisher} to honor backpressure as well.
* <dd>The operator honors downstream backpressure and expects both the source
* and inner {@code Publisher}s to honor backpressure as well.
* If this expectation is violated, the operator <em>may</em> throw an {@code IllegalStateException}.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code retryWhen} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/io/reactivex/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -3585,19 +3585,19 @@ public final Maybe<T> retryUntil(final BooleanSupplier stop) {
* resubscribe to the source Publisher.
* <p>
* <img width="640" height="430" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/retryWhen.f.png" alt="">
*
* <p>
* Example:
*
* This retries 3 times, each time incrementing the number of seconds it waits.
*
* <pre><code>
* Flowable.create((FlowableEmitter&lt;? super String&gt; s) -&gt; {
* Maybe.create((MaybeEmitter&lt;? super String&gt; s) -&gt; {
* System.out.println("subscribing");
* s.onError(new RuntimeException("always fails"));
* }, BackpressureStrategy.BUFFER).retryWhen(attempts -&gt; {
* return attempts.zipWith(Publisher.range(1, 3), (n, i) -&gt; i).flatMap(i -&gt; {
* System.out.println("delay retry by " + i + " second(s)");
* return Publisher.timer(i, TimeUnit.SECONDS);
* return Flowable.timer(i, TimeUnit.SECONDS);
* });
* }).blockingForEach(System.out::println);
* </code></pre>
Expand All @@ -3613,6 +3613,31 @@ public final Maybe<T> retryUntil(final BooleanSupplier stop) {
* delay retry by 3 second(s)
* subscribing
* } </pre>
* <p>
* Note that the inner {@code Publisher} returned by the handler function should signal
* either {@code onNext}, {@code onError} or {@code onComplete} in response to the received
* {@code Throwable} to indicate the operator should retry or terminate. If the upstream to
* the operator is asynchronous, signalling onNext followed by onComplete immediately may
* result in the sequence to be completed immediately. Similarly, if this inner
* {@code Publisher} signals {@code onError} or {@code onComplete} while the upstream is
* active, the sequence is terminated with the same signal immediately.
* <p>
* The following example demonstrates how to retry an asynchronous source with a delay:
* <pre><code>
* Maybe.timer(1, TimeUnit.SECONDS)
* .doOnSubscribe(s -&gt; System.out.println("subscribing"))
* .map(v -&gt; { throw new RuntimeException(); })
* .retryWhen(errors -&gt; {
* AtomicInteger counter = new AtomicInteger();
* return errors
* .takeWhile(e -&gt; counter.getAndIncrement() == 3)
* .flatMap(e -&gt; {
* System.out.println("delay retry by " + counter.get() + " second(s)");
* return Flowable.timer(counter.get(), TimeUnit.SECONDS);
* });
* })
* .blockingSubscribe(System.out::println, System.out::println);
* </code></pre>
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code retryWhen} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/io/reactivex/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9927,19 +9927,19 @@ public final Observable<T> retryUntil(final BooleanSupplier stop) {
* resubscribe to the source ObservableSource.
* <p>
* <img width="640" height="430" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/retryWhen.f.png" alt="">
*
* <p>
* Example:
*
* This retries 3 times, each time incrementing the number of seconds it waits.
*
* <pre><code>
* ObservableSource.create((Observer&lt;? super String&gt; s) -&gt; {
* Observable.create((ObservableEmitter&lt;? super String&gt; s) -&gt; {
* System.out.println("subscribing");
* s.onError(new RuntimeException("always fails"));
* }).retryWhen(attempts -&gt; {
* return attempts.zipWith(Observable.range(1, 3), (n, i) -&gt; i).flatMap(i -&gt; {
* System.out.println("delay retry by " + i + " second(s)");
* return ObservableSource.timer(i, TimeUnit.SECONDS);
* return Observable.timer(i, TimeUnit.SECONDS);
* });
* }).blockingForEach(System.out::println);
* </code></pre>
Expand All @@ -9955,6 +9955,31 @@ public final Observable<T> retryUntil(final BooleanSupplier stop) {
* delay retry by 3 second(s)
* subscribing
* } </pre>
* <p>
* Note that the inner {@code ObservableSource} returned by the handler function should signal
* either {@code onNext}, {@code onError} or {@code onComplete} in response to the received
* {@code Throwable} to indicate the operator should retry or terminate. If the upstream to
* the operator is asynchronous, signalling onNext followed by onComplete immediately may
* result in the sequence to be completed immediately. Similarly, if this inner
* {@code ObservableSource} signals {@code onError} or {@code onComplete} while the upstream is
* active, the sequence is terminated with the same signal immediately.
* <p>
* The following example demonstrates how to retry an asynchronous source with a delay:
* <pre><code>
* Observable.timer(1, TimeUnit.SECONDS)
* .doOnSubscribe(s -&gt; System.out.println("subscribing"))
* .map(v -&gt; { throw new RuntimeException(); })
* .retryWhen(errors -&gt; {
* AtomicInteger counter = new AtomicInteger();
* return errors
* .takeWhile(e -&gt; counter.getAndIncrement() == 3)
* .flatMap(e -&gt; {
* System.out.println("delay retry by " + counter.get() + " second(s)");
* return Observable.timer(counter.get(), TimeUnit.SECONDS);
* });
* })
* .blockingSubscribe(System.out::println, System.out::println);
* </code></pre>
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code retryWhen} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/io/reactivex/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -2692,6 +2692,31 @@ public final Single<T> retry(Predicate<? super Throwable> predicate) {
* function signals a value.
* <p>
* If the Publisher signals an onComplete, the resulting Single will signal a NoSuchElementException.
* <p>
* Note that the inner {@code Publisher} returned by the handler function should signal
* either {@code onNext}, {@code onError} or {@code onComplete} in response to the received
* {@code Throwable} to indicate the operator should retry or terminate. If the upstream to
* the operator is asynchronous, signalling onNext followed by onComplete immediately may
* result in the sequence to be completed immediately. Similarly, if this inner
* {@code Publisher} signals {@code onError} or {@code onComplete} while the upstream is
* active, the sequence is terminated with the same signal immediately.
* <p>
* The following example demonstrates how to retry an asynchronous source with a delay:
* <pre><code>
* Single.timer(1, TimeUnit.SECONDS)
* .doOnSubscribe(s -&gt; System.out.println("subscribing"))
* .map(v -&gt; { throw new RuntimeException(); })
* .retryWhen(errors -&gt; {
* AtomicInteger counter = new AtomicInteger();
* return errors
* .takeWhile(e -&gt; counter.getAndIncrement() == 3)
* .flatMap(e -&gt; {
* System.out.println("delay retry by " + counter.get() + " second(s)");
* return Flowable.timer(counter.get(), TimeUnit.SECONDS);
* });
* })
* .blockingSubscribe(System.out::println, System.out::println);
* </code></pre>
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code retryWhen} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down