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:
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) {
|
||||||
} 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user