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

fails handler in executeUnsafe

This commit is contained in:
InsanusMokrassar 2020-05-15 19:04:10 +06:00
parent f3827f81a7
commit db19b69ca0
2 changed files with 6 additions and 1 deletions

View File

@ -57,6 +57,7 @@
* 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 * `executeUnsafe` now working differently
* Now it is possible to pass exceptions handler into `executeUnsafe`
* `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

@ -34,19 +34,23 @@ fun <T: Any> RequestsExecutor.executeAsync(
suspend fun <T: Any> RequestsExecutor.executeUnsafe( suspend fun <T: Any> RequestsExecutor.executeUnsafe(
request: Request<T>, request: Request<T>,
retries: Int = 0, retries: Int = 0,
retriesDelay: Long = 1000L retriesDelay: Long = 1000L,
onAllFailed: (suspend (exceptions: Array<Exception>) -> Unit)? = null
): T? { ): T? {
var leftRetries = retries var leftRetries = retries
val exceptions = onAllFailed ?.let { mutableListOf<Exception>() }
do { do {
handleSafely( handleSafely(
{ {
leftRetries-- leftRetries--
delay(retriesDelay) delay(retriesDelay)
exceptions ?.add(it)
null null
} }
) { ) {
execute(request) execute(request)
} ?.let { return it } } ?.let { return it }
} while(leftRetries >= 0) } while(leftRetries >= 0)
onAllFailed ?.invoke(exceptions ?.toTypedArray() ?: emptyArray())
return null return null
} }