Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RetryWhen Example
delay retry by 1 second(s)
delay retry by 2 second(s)
delay retry by 3 second(s)
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Subscriber;
public class RetryWhenTests {
public static void main(String[] args) {
Observable.create((Subscriber<? super String> s) -> {
s.onError(new RuntimeException("always fails"));
}).retryWhen(attempts -> {
return attempts.zipWith(Observable.range(1, 3), (n, i) -> i).flatMap(i -> {
System.out.println("delay retry by " + i + " second(s)");
return Observable.timer(i, TimeUnit.SECONDS);
Copy link

jhalterman commented Jul 7, 2015

@benjchristensen When running this over an Observable.range(1, 10), I noticed the rx thread pool starts with 2 threads and grows up to 8, which is unexpected since this is the only callback/timer being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment