1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

Merge pull request #12 from InsanusMokrassar/0.9.2

0.9.2
This commit is contained in:
InsanusMokrassar 2019-01-31 10:01:00 +08:00 committed by GitHub
commit a501b7bba9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -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`

View File

@ -1,4 +1,4 @@
project.version = "0.9.1"
project.version = "0.9.2"
project.group = "com.github.insanusmokrassar"
buildscript {

View File

@ -164,16 +164,23 @@ fun <T: Any> RequestsExecutor.executeAsync(
fun <T: Any> RequestsExecutor.executeAsync(
request: Request<T>,
scope: CoroutineScope = GlobalScope
): Job {
): Deferred<T> {
return scope.async { execute(request) }
}
suspend fun <T: Any> RequestsExecutor.executeUnsafe(
request: Request<T>
request: Request<T>,
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
}
}
}