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`
* Typealias `ExceptionHandler` was added - it will be used for `handleSafely`
* `SetWebhook` factories signatures was changed (backward compatibility was not broken)
* `executeUnsafe` now working differently
* `TelegramBotAPI-extensions-api`:
* Long Polling extensions now are deprecated in this project. It was replaced into `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.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import com.github.insanusmokrassar.TelegramBotAPI.utils.handleSafely
import kotlinx.coroutines.*
@ -37,12 +38,15 @@ suspend fun <T: Any> RequestsExecutor.executeUnsafe(
): T? {
var leftRetries = retries
do {
try {
return execute(request)
} catch (e: RequestException) {
leftRetries--
delay(retriesDelay)
}
handleSafely(
{
leftRetries--
delay(retriesDelay)
null
}
) {
execute(request)
} ?.let { return it }
} while(leftRetries >= 0)
return null
}