diff --git a/CHANGELOG.md b/CHANGELOG.md index 04a9c2c6fe..4af16614a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,11 @@ must be regular text * Add `ResendableContent#createResends` which create adapted list of resends for content * Add `TextContent` own `createResends` realisation +### 0.9.2 + +* `RequestsExecutor#executeAsync(Request, CoroutineScope)` now will return `Deferred` for cases when you need result +* `RequestsExecutor#executeUnsafe` will automatically retry request if it was unsuccessful and retries > 0 + ### 0.8.5 * Add extension `String#toMarkdown` diff --git a/build.gradle b/build.gradle index 42460f767d..a45b9c6d9f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -project.version = "0.9.1" +project.version = "0.9.2" project.group = "com.github.insanusmokrassar" buildscript { 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 5d9165a40c..0264a29788 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 @@ -164,16 +164,23 @@ fun RequestsExecutor.executeAsync( fun RequestsExecutor.executeAsync( request: Request, scope: CoroutineScope = GlobalScope -): Job { +): Deferred { return scope.async { execute(request) } } suspend fun RequestsExecutor.executeUnsafe( - request: Request + request: Request, + retries: Int = 0, + retriesDelay: Long = 1000L ): T? { return try { execute(request) } catch (e: RequestException) { - null + if (retries > 0) { + delay(retriesDelay) + executeUnsafe(request, retries - 1, retriesDelay) + } else { + null + } } }