1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

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 ### 0.10.1
* Change algorithm of `executeUnsafe`: now it use loop instead of recursive calling
## 0.9.0 ## 0.9.0
* Old extension `OkHttpClient.Builder#useWith` now deprecated and must be replaced by the same in * 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, retries: Int = 0,
retriesDelay: Long = 1000L retriesDelay: Long = 1000L
): T? { ): T? {
return try { var leftRetries = retries
execute(request) while(true) {
} catch (e: RequestException) { try {
if (retries > 0) { return execute(request)
delay(retriesDelay) } catch (e: RequestException) {
executeUnsafe(request, retries - 1, retriesDelay) if (leftRetries > 0) {
} else { leftRetries--
null delay(retriesDelay)
} else {
return null
}
} }
} }
} }