executeUnsafe to loop

This commit is contained in:
InsanusMokrassar 2019-02-14 16:45:25 +08:00
parent 90c3cd1b23
commit 4003fdbcd1
2 changed files with 13 additions and 8 deletions

View File

@ -13,6 +13,8 @@
### 0.10.1
* Change algorithm of `executeUnsafe`: now it use loop instead of recursive calling
## 0.9.0
* Old extension `OkHttpClient.Builder#useWith` now deprecated and must be replaced by the same in

View File

@ -173,14 +173,17 @@ suspend fun <T: Any> RequestsExecutor.executeUnsafe(
retries: Int = 0,
retriesDelay: Long = 1000L
): T? {
return try {
execute(request)
} catch (e: RequestException) {
if (retries > 0) {
delay(retriesDelay)
executeUnsafe(request, retries - 1, retriesDelay)
} else {
null
var leftRetries = retries
while(true) {
try {
return execute(request)
} catch (e: RequestException) {
if (leftRetries > 0) {
leftRetries--
delay(retriesDelay)
} else {
return null
}
}
}
}