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

change mechanism of executeUnsafe

This commit is contained in:
InsanusMokrassar 2020-05-15 18:59:42 +06:00
parent 0532dbb1ae
commit f3827f81a7
2 changed files with 11 additions and 6 deletions

View File

@ -56,6 +56,7 @@
* All `setWebhook` extensions was marked as deprecated, renamed and replaced into `TelegramBotAPI-extensions-utils` * All `setWebhook` extensions was marked as deprecated, renamed and replaced into `TelegramBotAPI-extensions-utils`
* Typealias `ExceptionHandler` was added - it will be used for `handleSafely` * Typealias `ExceptionHandler` was added - it will be used for `handleSafely`
* `SetWebhook` factories signatures was changed (backward compatibility was not broken) * `SetWebhook` factories signatures was changed (backward compatibility was not broken)
* `executeUnsafe` now working differently
* `TelegramBotAPI-extensions-api`: * `TelegramBotAPI-extensions-api`:
* Long Polling extensions now are deprecated in this project. It was replaced into `TelegramBotAPI-extensions-utils` * Long Polling extensions now are deprecated in this project. It was replaced into `TelegramBotAPI-extensions-utils`
* `TelegramBotAPI-extensions-utils`: * `TelegramBotAPI-extensions-utils`:

View File

@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.types.Response import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import com.github.insanusmokrassar.TelegramBotAPI.utils.handleSafely
import kotlinx.coroutines.* import kotlinx.coroutines.*
@ -37,12 +38,15 @@ suspend fun <T: Any> RequestsExecutor.executeUnsafe(
): T? { ): T? {
var leftRetries = retries var leftRetries = retries
do { do {
try { handleSafely(
return execute(request) {
} catch (e: RequestException) { leftRetries--
leftRetries-- delay(retriesDelay)
delay(retriesDelay) null
} }
) {
execute(request)
} ?.let { return it }
} while(leftRetries >= 0) } while(leftRetries >= 0)
return null return null
} }