Last active
February 1, 2016 02:02
-
-
Save danylovolokh/e30e368bccba0e6eff9e to your computer and use it in GitHub Desktop.
Server polling and retry operations when failed. With Retrofit and RxJava.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repeatWhen(new Func1<Observable<? extends Void>, Observable<?>>() { | |
@Override | |
public Observable<?> call(Observable<? extends Void> observable) { | |
Log.v(TAG, "repeatWhen, call"); | |
return observable.flatMap(new Func1<Void, Observable<?>>() { | |
@Override | |
public Observable<?> call(Void aVoid) { | |
if(mCounter > ATTEMPTS){ | |
// terminate by ourselves | |
throw new RuntimeException(); | |
} | |
return Observable.timer(mCounter++ * ORIGINAL_DELAY_IN_SECONDS, TimeUnit.SECONDS); | |
} | |
}); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment