diff --git a/CHANGELOG.md b/CHANGELOG.md index eaa5d4c2aa..a7aaf9caed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/RequestsExecutor.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/RequestsExecutor.kt index 1c621db8b0..6f0c2e0767 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/RequestsExecutor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/RequestsExecutor.kt @@ -173,14 +173,17 @@ suspend fun 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 + } } } }