mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
executeUnsafe to loop
This commit is contained in:
parent
90c3cd1b23
commit
4003fdbcd1
@ -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
|
||||||
|
@ -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) {
|
||||||
|
try {
|
||||||
|
return execute(request)
|
||||||
} catch (e: RequestException) {
|
} catch (e: RequestException) {
|
||||||
if (retries > 0) {
|
if (leftRetries > 0) {
|
||||||
|
leftRetries--
|
||||||
delay(retriesDelay)
|
delay(retriesDelay)
|
||||||
executeUnsafe(request, retries - 1, retriesDelay)
|
|
||||||
} else {
|
} else {
|
||||||
null
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user