mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 19:48:43 +00:00
change mechanism of executeUnsafe
This commit is contained in:
parent
0532dbb1ae
commit
f3827f81a7
@ -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`:
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user