Last active
August 31, 2020 10:19
-
-
Save pamartineza/6d4b6134b1909cd3e10628463f2bb71f to your computer and use it in GitHub Desktop.
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
//Our function Zips error emissions with a range to limit them to 3, | |
// and emits a 0L with a power of 2 based delay | |
webservice.getRequestSingle() | |
.retryWhen { errors: Flowable<Throwable> -> | |
errors.zipWith( | |
Flowable.range(1,3) | |
BiFunction<Throwable, Int, Int> { error: Throwable, retryCount: Int -> | |
retryCount | |
} | |
).flatMap { retryCount: Int -> | |
Flowable.timer( | |
Math.pow(2.toDouble(), retryCount.toDouble()).toLong(), | |
TimeUnit.SECONDS | |
) | |
} | |
} | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe({ data -> | |
//refreshScreenWithData | |
}, { error -> | |
//handle error | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the article.
Small typoes: