Skip to content

Instantly share code, notes, and snippets.

@Shivamdhuria
Last active December 12, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shivamdhuria/05d929c01c11fba95d0f591be2193e8f to your computer and use it in GitHub Desktop.
Save Shivamdhuria/05d929c01c11fba95d0f591be2193e8f to your computer and use it in GitHub Desktop.
val dogImagesFlow = getDogImages().flowOn(Dispatchers.IO)
.retryWhen { cause, attempt ->
if (cause is IOException && attempt < 3) {
val delay = 2000 * (attempt + 1)
emit(
ResultWrapper.NetworkError(
"Attempt No ${attempt + 1} Failed.Retrying again in time ${delay / 1000} sec...",
delay.toInt()
)
)
delay(delay)
return@retryWhen true
} else {
emit(ResultWrapper.NetworkError("Retries Expired!", null))
return@retryWhen false
}
}.catch {
//catch Exception
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment